Hi everyone, I’m hoping someone can shed some light on some difficulties I am having programming my Arduino.
I have written a program for my project at university. Basically it is designed to turn on or off an output (pin 12) dependant on 3 variables.
The first variable is a wireless receiver (pin 2), and the other two are switches (pin 3 and pin 4 - set high).
So, I want to make pin 12 high when pin 2 AND pin 3 are high. (Pin 12 latched on, pin 2 is a momentary press of a button and will become low again after button is released.)
I then want a timer to run for 10 seconds while pin 12 is high.
I want one of three scenarios to make pin 12 low.
Either the timer runs out OR pin 3 is made low OR pin 4 is made low.
At present I have this all working, except the timer. I have been working on the timer for nearly two days now.
I tried using millis, however the timer is erratic. I believe this is because pin 12 isn’t always high, whilst the Arduino is constantly checking to see if the current time - previous time is more than 10 seconds. So, it cycles every 10 seconds and not when pin 12 is high.
I also attempted to use the for function, with no success.
I also tried to do a simple count loop. N=N-1 - loops until N=0 at which point it would make pin 12 low. Didn’t work.
I am sure I am missing something really simple here and I have done many searches to try and help.
I hope this makes sense!