Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SimpleTimer.h>
- SimpleTimer timer;
- int outPin = 9; // output pin (relay)
- int inPin = 8; // choose the input pin (for a pushbutton)
- int outVal = LOW;
- int val = 0; // variable for reading the pin status
- int prevVal = 0;
- long TIMEOUT = 60000UL; // 1 minute
- //long TIMEOUT = 420000UL; // 7 minutes
- void turnOn() {
- outVal = HIGH;
- digitalWrite(outPin, outVal);
- }
- void turnOff() {
- outVal = LOW;
- digitalWrite(outPin, outVal);
- }
- bool alreadyOn() {
- return outVal == HIGH;
- }
- void setup() {
- pinMode(outPin, OUTPUT);
- pinMode(inPin, INPUT);
- turnOff();
- }
- void loop() {
- prevVal = val;
- val = digitalRead(inPin);
- if (val == LOW && prevVal == HIGH) {
- if (alreadyOn()) {
- turnOff();
- } else {
- turnOn();
- timer.setTimeout(TIMEOUT, turnOff);
- }
- }
- timer.run();
- }
Add Comment
Please, Sign In to add comment