@@ -24,23 +24,25 @@ void setup() {
24
24
// Turn on the LEDs above buttons A, B, and C
25
25
buttons.setLeds (true , true , true );
26
26
}
27
+
27
28
void loop () {
28
29
// Check for new button events, returns true when button state changes
29
30
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' )) {
33
35
Serial.println (" Button A pressed!" );
34
36
button_a = !button_a;
35
- } else if (buttons.isPressed (1 )) {
37
+ } else if (buttons.isPressed (" B " )) {
36
38
Serial.println (" Button B pressed!" );
37
39
button_b = !button_b;
38
- } else if (buttons.isPressed (2 )) {
40
+ } else if (buttons.isPressed (' C ' )) {
39
41
Serial.println (" Button C pressed!" );
40
42
button_c = !button_c;
41
43
}
42
-
43
- // Update the LEDs above buttons, depending on the variables value
44
+
45
+ // Update the LEDs above buttons, depending on the variables' value
44
46
buttons.setLeds (button_a, button_b, button_c);
45
47
}
46
48
}
0 commit comments