#include <Arduino.h>
#include <OneButton.h>
// Setup a new OneButton on pin A1.
OneButton buttonRed(A2);
OneButton buttonGreen(A1);
typedef enum {
ACTION_WORK, // set LED "OFF".
ACTION_SETUP // set LED "ON"
} MyActions;
MyActions nextAction = ACTION_WORK; // no action when starting
// setup code here, to run once:
void setup() {
// enable the standard led on pin 13.
pinMode(13, OUTPUT); // sets the digital pin as output
// link the doubleclick function to be called on a doubleclick event.
buttonRed.attachDoubleClick(doubleclick);
buttonGreen.attachDoubleClick(doubleclick);
} // setup
// main code here, to run repeatedly:
void loop() {
// keep watching the push button:
buttonRed.tick();
buttonGreen.tick();
Serial.print(nextAction);
Serial.println();
// You can implement other code in here or just wait a while
delay(10);
} // loop
// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick() {
static int m = LOW;
// reverse the LED
m = !m;
digitalWrite(13, m);
if (nextAction == ACTION_WORK) {
nextAction = ACTION_SETUP;
} else if (nextAction == ACTION_SETUP) {
nextAction = ACTION_WORK;
}
} // doubleclick