Skip to content

Instantly share code, notes, and snippets.

@rodrigopmatias
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigopmatias/25970d3b4f4109a878ff to your computer and use it in GitHub Desktop.
Save rodrigopmatias/25970d3b4f4109a878ff to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#define PIN_BTN 14
#define PIN_LED 13
#define MAX_TIMER 30
uint8_t counter;
enum state {
ON,
OFF
};
state control;
void setup() {
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_BTN, INPUT);
counter = 0;
control = OFF;
}
void loop() {
if(control == OFF && digitalRead(PIN_BTN) == HIGH) {
control = ON;
counter = 0;
digitalWrite(PIN_LED, HIGH);
}
else if(control == ON && counter <= MAX_TIMER) {
counter++;
}
else if(control == ON && count > MAX_TIMER) {
control = OFF;
digitalWrite(LED_PIN, LOW);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment