Skip to content

Commit 59aef64

Browse files
committed
Update example to document support for both numeric and letter indices ♻️
1 parent 53c079c commit 59aef64

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/Modulino_Buttons/Buttons_Basic/Buttons_Basic.ino

+9-7
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ void setup() {
2424
// Turn on the LEDs above buttons A, B, and C
2525
buttons.setLeds(true, true, true);
2626
}
27+
2728
void loop() {
2829
// Check for new button events, returns true when button state changes
2930
if (buttons.update()) {
30-
// Check which button was pressed (0=A, 1=B, 2=C)
31-
// Also toggle the corresponding LED, for each of the three buttons
32-
if (buttons.isPressed(0)) {
31+
// You can use either index (0=A, 1=B, 2=C) or letter ('A', 'B', 'C') to check buttons
32+
// Below we use the letter-based method for better readability
33+
34+
if (buttons.isPressed('A')) {
3335
Serial.println("Button A pressed!");
3436
button_a = !button_a;
35-
} else if (buttons.isPressed(1)) {
37+
} else if (buttons.isPressed("B")) {
3638
Serial.println("Button B pressed!");
3739
button_b = !button_b;
38-
} else if (buttons.isPressed(2)) {
40+
} else if (buttons.isPressed('C')) {
3941
Serial.println("Button C pressed!");
4042
button_c = !button_c;
4143
}
42-
43-
// Update the LEDs above buttons, depending on the variables value
44+
45+
// Update the LEDs above buttons, depending on the variables' value
4446
buttons.setLeds(button_a, button_b, button_c);
4547
}
4648
}

0 commit comments

Comments
 (0)