#include <OneButton.h>
const uint8_t whiteLed_pin = 12;
const uint8_t yellowLed_pin = 11;
const uint8_t button_pin = 10;
OneButton button( button_pin, true, true );
void setLeds( const bool white, const bool yellow )
{
Serial.print( "White " );
Serial.print( white == true ? "ON" : "OFF" );
Serial.print( ", Yellow " );
Serial.println( yellow == true ? "ON" : "OFF" );
digitalWrite( whiteLed_pin, white == true ? HIGH : LOW );
delay(10);
digitalWrite( yellowLed_pin, yellow == true ? HIGH : LOW );
}
void setup()
{
Serial.begin( 115200 );
pinMode( whiteLed_pin, OUTPUT );
pinMode( yellowLed_pin, OUTPUT );
setLeds( true, false );
button.setDebounceTicks( 25 );
button.setClickTicks( 150 );
button.setPressTicks( 500 );
static bool state = false;
button.attachClick( []()
{
setLeds( state, !state );
state = !state;
}
);
button.attachDoubleClick( []()
{
setLeds( true, true );
state = true;
}
);
button.attachLongPressStart( []()
{
setLeds( false, false );
state = true;
}
);
}
void loop()
{
button.tick();
}