Skip to content

Commit fd69d03

Browse files
authored
Merge pull request #30 from Xayton/improve-buttons-example
Update buttons example: toggle LEDs when pushing buttons
2 parents d0c12de + b57e5d6 commit fd69d03

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

examples/Modulino_Buttons/Buttons_Basic/Buttons_Basic.ino

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
// Create a ModulinoButtons object
1212
ModulinoButtons buttons;
1313

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;
1717

1818
void setup() {
1919
Serial.begin(9600);
@@ -28,12 +28,19 @@ void loop() {
2828
// Check for new button events, returns true when button state changes
2929
if (buttons.update()) {
3030
// Check which button was pressed (0=A, 1=B, 2=C)
31+
// Also toggle the corresponding LED, for each of the three buttons
3132
if (buttons.isPressed(0)) {
3233
Serial.println("Button A pressed!");
34+
button_a = !button_a;
3335
} else if (buttons.isPressed(1)) {
3436
Serial.println("Button B pressed!");
37+
button_b = !button_b;
3538
} else if (buttons.isPressed(2)) {
3639
Serial.println("Button C pressed!");
40+
button_c = !button_c;
3741
}
42+
43+
// Update the LEDs above buttons, depending on the variables value
44+
buttons.setLeds(button_a, button_b, button_c);
3845
}
3946
}

0 commit comments

Comments
 (0)