-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonTest.cpp
59 lines (45 loc) · 1.34 KB
/
buttonTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
int led1Pin = 13;
int led2Pin = 12;
int buttonPin = A0;
int delayDuration = 1000; // in milliseconds
int eventCounter = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
}
void loop() {
if (digitalRead(buttonPin) == HIGH) {
if (eventCounter == 0) {
// blink led 1 3 times
for (int i = 0; i < 3; i++) {
digitalWrite(led1Pin, HIGH);
delay(delayDuration);
digitalWrite(led1Pin, LOW);
delay(delayDuration);
}
}
if (eventCounter == 1) {
// blink led 2 3 times
for (int i = 0; i < 3; i++) {
digitalWrite(led2Pin, HIGH);
delay(delayDuration);
digitalWrite(led2Pin, LOW);
delay(delayDuration);
}
}
if (eventCounter == 2) {
// blink both leds 3 times
for (int i = 0; i < 3; i++) {
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, HIGH);
delay(delayDuration);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
delay(delayDuration);
}
}
// update event
eventCounter = (eventCounter + 1) % 3;
}
}