File tree 1 file changed +10
-3
lines changed
examples/Modulino_Buttons/Buttons_Basic
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 11
11
// Create a ModulinoButtons object
12
12
ModulinoButtons buttons;
13
13
14
- bool button_a = false ;
15
- bool button_b = false ;
16
- bool button_c = false ;
14
+ bool button_a = true ;
15
+ bool button_b = true ;
16
+ bool button_c = true ;
17
17
18
18
void setup () {
19
19
Serial.begin (9600 );
@@ -28,12 +28,19 @@ void loop() {
28
28
// Check for new button events, returns true when button state changes
29
29
if (buttons.update ()) {
30
30
// Check which button was pressed (0=A, 1=B, 2=C)
31
+ // Also toggle the corresponding LED, for each of the three buttons
31
32
if (buttons.isPressed (0 )) {
32
33
Serial.println (" Button A pressed!" );
34
+ button_a = !button_a;
33
35
} else if (buttons.isPressed (1 )) {
34
36
Serial.println (" Button B pressed!" );
37
+ button_b = !button_b;
35
38
} else if (buttons.isPressed (2 )) {
36
39
Serial.println (" Button C pressed!" );
40
+ button_c = !button_c;
37
41
}
42
+
43
+ // Update the LEDs above buttons, depending on the variables value
44
+ buttons.setLeds (button_a, button_b, button_c);
38
45
}
39
46
}
You can’t perform that action at this time.
0 commit comments