#include <JC_Button.h>
Button button( 9 );
void setup()
{
Serial.begin( 115200 );
pinMode( LED_BUILTIN, OUTPUT );
digitalWrite( LED_BUILTIN, LOW );
button.begin();
}
void loop()
{
static uint32_t timer = 0;
button.read();
if ( button.wasReleased() )
{
if ( timer == 0 )
{
Serial.println( "timer started" );
digitalWrite( LED_BUILTIN, HIGH );
}
else
{
Serial.println( "timer restarted" );
}
timer = millis();
}
if ( timer != 0 && millis() - timer >= 5000UL )
{
Serial.println( "timer finished" );
digitalWrite( LED_BUILTIN, LOW );
timer = 0;
}
}