#define MAX8BUTTONS // To save RAM if only up to 8 buttons are used
#include <MobaTools.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int SHORT_PRESS_TIME = 1000; // 1000 milliseconds
const int LONG_PRESS_TIME = 1000; // 1000 milliseconds
const int ledPin[8] = {22, 28, 34, 40, 23, 29, 35, 41}; // the pin that the LED is attached to
const byte buttonPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // create ezButton object that attach to pin 7;
int number_led = 8;
int NUMBER_BUTTONS = sizeof(buttonPins);
MoToButtons myButtons ( buttonPins, NUMBER_BUTTONS, 50, LONG_PRESS_TIME ) ;
void setup() {
Serial.begin(9600);
for (byte n = 0; n <= number_led; n++) {
pinMode(ledPin[n], OUTPUT);
}
}
void loop() {
myButtons.processButtons();
for (int i = 0; i < (NUMBER_BUTTONS); i = i + 1) {
if (myButtons.pressed(i)) {
Serial.print("Button Pressed ");
Serial.println(i);
}
if ( myButtons.longPress(i) ) {
Serial.print("Button ");
Serial.print(i);
Serial.print(" - A long press is detected - ");
for (byte n = 0; n < NUMBER_BUTTONS; n++) {
digitalWrite(ledPin[n], LOW);
}
digitalWrite(ledPin[i], HIGH);
Serial.print("LED ");
Serial.println(i);
}
if ( myButtons.shortPress(i) ) {
Serial.print("Button ");
Serial.print(i);
Serial.println(" - A short press is detected - ");
}
}
}