File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
examples/Modulino_Buttons/Buttons_Basic Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 1111// Create a ModulinoButtons object
1212ModulinoButtons 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
1818void 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}
You can’t perform that action at this time.
0 commit comments