Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "Arduino.h"
#define BUTTON_PIN 3
#define DELAY 30000 //milliseconds
static unsigned long time;
static unsigned int state;
static unsigned int button;
static unsigned int delay;
void setup()
{
time = 0;
state = 1;
}
void loop()
{
button = digitalRead(BUTTON_PIN);
switch state
{
case 1:
if(button == HIGH) { // enter next state and save current time
state = 2;
time = millis();
}
break;
case 2:
if(button == HIGH) // reset timer
time = millis();
if(time - millis() > DELAY) //check if time has passed
state = 1;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.