mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 19:36:26 +02:00
[ES] Blatt 1 und 2 hinzugefügt
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
37
es/blatt1/uebung1-13/uebung1-13.ino
Normal file
37
es/blatt1/uebung1-13/uebung1-13.ino
Normal file
@ -0,0 +1,37 @@
|
||||
int ledPin = 7;
|
||||
int buttonPin = 5;
|
||||
int buttonState;
|
||||
bool volatile ledState = true;
|
||||
bool volatile performDelay = false;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
pinMode(buttonPin, INPUT);
|
||||
attachInterrupt(buttonPin, buttonChanged, RISING);
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
if (performDelay) {
|
||||
detachInterrupt(buttonPin);
|
||||
delay(20);
|
||||
performDelay = false;
|
||||
attachInterrupt(buttonPin, buttonChanged, RISING);
|
||||
|
||||
if (buttonState == HIGH) {
|
||||
if (ledState) {
|
||||
digitalWrite(ledPin, LOW);
|
||||
} else {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
ledState = !ledState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void buttonChanged() {
|
||||
performDelay = true;
|
||||
}
|
||||
Reference in New Issue
Block a user