#include "OneButton.h" // Include the OneButton library
OneButton button(A0, true); // Attach a button on pin A0 to the library
#define L1 2
#define L2 3
#define L3 4
int RLY1 = LOW;
int RLY2 = LOW;
int RLY3 = LOW;
void setup() {
pinMode(L1, OUTPUT); // Set the digital pin as output
pinMode(L2, OUTPUT); // Set the digital pin as output
pinMode(L3, OUTPUT); // Set the digital pin as output
button.attachDoubleClick(doubleclick); // Link the function to be called on a double-click event
button.attachClick(singleclick); // Link the function to be called on a single-click event
button.attachLongPressStop(longclick); // Link the function to be called on a long-press event
}
void loop() {
button.tick(); // Check the status of the button
}
void doubleclick() { // What happens when the button is double-clicked
RLY1 = !RLY1;
digitalWrite(L1, RLY1);
}
void singleclick() { // What happens when the button is clicked
RLY2 = !RLY2;
digitalWrite(L2, RLY2);
}
void longclick() { // What happens when the button is long-pressed
RLY3 = !RLY3;
digitalWrite(L3, RLY3);
}