// https://wokwi.com/projects/426072066599819265
// Based on
// https://github.com/ArduinoGetStarted/button/blob/master/examples/05.MultipleButtonAll/05.MultipleButtonAll.ino
// See https://forum.arduino.cc/t/6-accelsteppers-as-an-array-of-struct-array-of-class-array-of-object/1311789/5
//
/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/tutorials/arduino-button-library
This example:
+ uses debounce for multiple buttons.
+ reads state of multiple buttons
+ detects the pressed and released events of multiple buttons
*/
const bool VERBOSE = false;
#include <ezButton.h> // https://github.com/ArduinoGetStarted/button
ezButton buttons[] {6, 7, 8, 9, 10, 11, 12}; //
const int NumButtons = sizeof(buttons) / sizeof(buttons[0]);
const char *name[NumButtons] = {"red", "green", "blue", "yellow", "black", "B-2", "B-3"};
void setup() {
Serial.begin(115200);
for (auto &button : buttons) {
button.setDebounceTime(50); // set debounce time to 50 milliseconds
}
}
void loop() {
int btnState[NumButtons];
int ii = 0;
for (auto &button : buttons) {
button.loop(); // MUST call the loop() function first
btnState[ii] = button.getState();
if (VERBOSE) {
Serial.print("button ");
Serial.print(ii );
Serial.print(name[ii]);
Serial.print(" state: ");
Serial.println(btnState[ii]);
}
if ( button.isPressed()) {
Serial.print("The button ");
Serial.print(ii );
Serial.print(name[ii]);
Serial.println(" is pressed");
}
if ( button.isReleased()) {
Serial.print("The button ");
Serial.print(ii );
Serial.print(name[ii]);
Serial.println(" is released");
}
++ii; // Inrement counter for next iteration
}
}