@@ -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+
2728void 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