Last active
August 29, 2015 14:02
-
-
Save rodrigopmatias/25970d3b4f4109a878ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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