1
0
mirror of https://github.com/2martens/uni.git synced 2026-05-06 11:26:25 +02:00
Files
uni/es/blatt1/uebung1-15b/uebung1-15b.ino
2015-04-21 23:49:42 +02:00

41 lines
729 B
C++

int ledPin = 7;
int buttonPlusPin = 5;
int buttonMinusPin = 3;
int volatile counter = 0;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPlusPin, INPUT);
pinMode(buttonMinusPin, INPUT);
attachInterrupt(buttonPlusPin, increment, LOW);
attachInterrupt(buttonMinusPin, decrement, LOW);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (counter > 255) {
counter = 255;
}
if (counter < 0) {
counter = 0;
}
analogWrite(ledPin, counter);
Serial.print("LED: ");
Serial.println(counter);
delay(50);
}
void increment() {
counter += 1;
delayMicroseconds(50000);
}
void decrement() {
counter -= 1;
delayMicroseconds(50000);
}