Hi All
I require the input of the knowledgable
I have set a delay on UNO to delay a lock from opening, all good, it works, however i cannot seem to figure out how to get it back to its original state after the lock has been released.
So in this instance, UNO delays trigger for 15 min, then releases door lock after 15 min has lapsed, then has to, after 1 min, go back into locked state.
My code below..
int pbuttonPin=2;
int relayPin=3;
int val=0;
int magOff=0;
int pushed=0;
int led = 13; // Pin 13 has an LED connected on most Arduino boards.
unsigned long DELAY_TIME = 30000; // 10 sec
unsigned long delayStart = 0; // the time the delay started
bool delayRunning = false; // true if still waiting for delay to finish
void setup() {
// put your setup code here, to run once:
pinMode(pbuttonPin, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // turn MAGLOCK OFF
// start delay
delayStart = millis();
delayRunning = true;
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(pbuttonPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
} else
if (delayRunning && ((millis() - delayStart) >= DELAY_TIME)) {
delayRunning = false; // finished delay -- single shot, once only
digitalWrite(relayPin, HIGH); // turn MAGLOCK ON
}
}