I'm looking for an elegant way to add timed press to this. Right now this toggles on each press. I'd like it to toggle only after holding down for 1 second. Do you see a nice way to add that?
(I've skipped the variable definitions here for simplicity)
void loop()
{
mode_switch_reading = digitalRead(mode_switch);
if (mode_switch_reading == LOW && previous_mode_switch_reading == HIGH && millis() - last_debounce_time_for_mode_switch > defined_debounce_time)
{
last_debounce_time_for_mode_switch = millis();
if (mode_switch_state == LOW)
{
mode_switch_state = HIGH;
}
else // HIGH, so make it low
{
mode_switch_state = LOW;
}
}
previous_mode_switch_reading = mode_switch_reading;
}