Little bit of help needed with Millis()
in
Integration and Hardware
•
2 years ago
I have a section of code that loops every 5 seconds and switches an LED to be on or off for those 5 seconds.
What I'm aiming to do, is have the LED switch on for 1 second, and switch off for the remainding 4 seconds, while still having the loop run a second time and keep the LED off for 5 seconds.
I tried using a delay in the space I've commented below, but the delay stops all input from processing for that amount of time which I don't want.
Can anyone help?
Thanks
What I'm aiming to do, is have the LED switch on for 1 second, and switch off for the remainding 4 seconds, while still having the loop run a second time and keep the LED off for 5 seconds.
I tried using a delay in the space I've commented below, but the delay stops all input from processing for that amount of time which I don't want.
Can anyone help?
Thanks
- if (red == true) {
while (millis() >= time + 5000)
{
// turn LED on/off:
LEDVal = 1 - LEDVal;
if(LEDVal == 1) {
arduino.digitalWrite(redledPin, arduino.HIGH);
// this is where I would like the LED to only be on for 1 second, and switch off for the remaining time.
}
else if(LEDVal == 0) {
arduino.digitalWrite(redledPin, arduino.LOW);
}
time = millis(); //record current time
}
1