I have a nano watching sensors. when a sensor see something it toggles an led but that confuses people. I would like to be able to have the led turn on for 1/2 second then off but I can's use a delay because I need to be watching for more inputs from the sensors. I'd like if it sees an input and then 1/4 second later sees another one it just stays on 1/2 second from the last input.
The sensors are IR sensors and I'm using the code from Arduino Tutorials | tronixstuff.com so timer 2 is already used.
Is there a way I can set up another timer so that I can set it and it will turn on a pin for 1/2 second then turn it off and then do nothing until I trigger it again?
Thanks
You dont have to use a timer, use millis()
bool startBlink = false;
bool ledOn = false;
unsigned long blinkStarted;
void loop() {
startBlink = true; // this triggers the blink
if (startBlink) {
startBlink = false;
blinkStarted = millis();
ledOn = true;
digitalWrite(13, HIGH);
}
if (ledOn && ((millis() - blinkStarted) >= 500)) {
ledOn = false;
digitalWrite(13, HIGH);
}
}
looks like exactly what I wanted, thanks