#include <JC_Button.h> // https://github.com/JChristensen/JC_Button
Button button_increase( 4 );
Button button_decrease( 5 );
void setup()
{
Serial.begin( 115200 );
button_increase.begin();
button_decrease.begin();
}
void loop()
{
button_increase.read();
button_decrease.read();
static const uint8_t times[] = { 5, 10, 20, 30, 60, 120 };
static const uint8_t times_count = sizeof( times ) / sizeof( times[0] );
static int8_t index = 0;
static int8_t index_previous = -1;
if ( index < times_count - 1 && button_increase.wasReleased() )
{
++index;
}
else if ( index > 0 && button_decrease.wasReleased() )
{
--index;
}
/* alternative behavior
if ( button_increase.wasReleased() && ++index == times_count )
{
index = 0;
}
else if ( button_decrease.wasReleased() && --index == -1 )
{
index = times_count - 1;
}
*/
if ( index_previous != index )
{
index_previous = index;
uint8_t time = times[index];
Serial.print( "time = " );
Serial.println( time );
}
}