Skip to content

Instantly share code, notes, and snippets.

@BeckmaR
Created June 20, 2016 08:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeckmaR/abb2896cb8b5342533adfc04bba026e9 to your computer and use it in GitHub Desktop.
Save BeckmaR/abb2896cb8b5342533adfc04bba026e9 to your computer and use it in GitHub Desktop.
#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