Knowledge Base Nr: 00328 arduino1.cpp - http://www.swe-kaiser.de
Downloads:
c/cpp: mein erstes programm für ARDUINO
int ledPin = 13;
int tonPin = 11;
int irqPin = 2;
int potiPin = 0;
int i = 0;
volatile int soundOn = LOW;
void setup()
{
pinMode(ledPin, OUTPUT);
attachInterrupt(0, interrupt, LOW); //irq0 = pin2
Serial.begin(19200);
}
void loop()
{
i = analogRead(potiPin);
if (soundOn == HIGH)
tone(tonPin, i);
else
noTone(tonPin);
Serial.print("Wert: ");
Serial.println(i);
digitalWrite(ledPin, HIGH);
delay(i);
digitalWrite(ledPin, LOW);
delay(i);
}
void interrupt()
{
soundOn = !soundOn;
if (soundOn == HIGH)
tone(tonPin, i);
else
noTone(tonPin);
Serial.println("Interrupt!");
while (digitalRead(irqPin) == LOW) //entprellen
/* wait */ ;
}