#include "OneButton.h" //we need the OneButton library
OneButton button(A0, true); //attach a button on pin A0 to the library
#define L1 2
int RLY1 = LOW;
#define L2 3
int RLY2 = LOW;
#define L3 4
int RLY3 = LOW;
void setup() {
pinMode(L1, OUTPUT); // sets the digital pin as output
pinMode(L2, OUTPUT); // sets the digital pin as output
pinMode(L3, OUTPUT); // sets the digital pin as output
button.attachDoubleClick(doubleclick); // link the function to be called on a doubleclick event.
button.attachClick(singleclick); // link the function to be called on a singleclick event.
button.attachLongPressStop(longclick); // link the function to be called on a longpress event.
}
void loop() {
button.tick(); // check the status of the button
delay(10); // a short wait between checking the button
} // loop
void doubleclick() { // what happens when button is double-clicked
RLY1 = ~ RLY1;
digitalWrite(L1,RLY1);
delay(250);
}
void singleclick(){ // what happens when the button is clicked
RLY2 = ~ RLY2;
digitalWrite(L2,RLY2);
delay(250);
}
void longclick(){ // what happens when buton is long-pressed
RLY3 = ~ RLY3;
digitalWrite(L3,RLY3);
delay(250);
// turn off the blue Relay
}