#include "OneButton.h"
OneButton button1( 5 );
const uint8_t ledPin = LED_BUILTIN;
void toggleLED()
{
static bool state = false;
state = !state;
digitalWrite( ledPin, state == true ? HIGH : LOW );
Serial.print( "LED is " );
Serial.println( state == true ? "ON" : "OFF" );
}
void button1LongPress()
{
toggleLED(); // invert the state of the LED
}
void setup()
{
Serial.begin( 115200 );
pinMode( ledPin, OUTPUT );
toggleLED(); // turn on the LED
button1.setPressTicks( 2500 ); // a long press will be detected after 2500 ms
button1.attachLongPressStart( button1LongPress ); // function to be called once, while the button is pressed
//button1.attachLongPressStop( button1LongPress ); // function to be called when the button was released
}
void loop()
{
button1.tick();
}