Skip to content

Update buttons example: toggle LEDs when pushing buttons #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions examples/Modulino_Buttons/Buttons_Basic/Buttons_Basic.ino
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@
// Create a ModulinoButtons object
ModulinoButtons buttons;

bool button_a = false;
bool button_b = false;
bool button_c = false;
bool button_a = true;
bool button_b = true;
bool button_c = true;

void setup() {
Serial.begin(9600);
@@ -28,12 +28,19 @@ void loop() {
// Check for new button events, returns true when button state changes
if (buttons.update()) {
// Check which button was pressed (0=A, 1=B, 2=C)
// Also toggle the corresponding LED, for each of the three buttons
if (buttons.isPressed(0)) {
Serial.println("Button A pressed!");
button_a = !button_a;
} else if (buttons.isPressed(1)) {
Serial.println("Button B pressed!");
button_b = !button_b;
} else if (buttons.isPressed(2)) {
Serial.println("Button C pressed!");
button_c = !button_c;
}

// Update the LEDs above buttons, depending on the variables value
buttons.setLeds(button_a, button_b, button_c);
}
}