Hello!
I am very new with arduino and have been searching and trying to implement a code that makes a led blink with two different intervals without using the function delay. I have seen the code of "blink without delay" (http://arduino.cc/en/Tutorial/BlinkWithoutDelay) and understand it but I have not been able to modify the code in order for it to make the following.
Turn the led on for 5 seconds.
Turn the led off for 9 seconds.
I know it shouldn´t be so difficult but all the codes I find in the web use the same delay between on/off, making it a lot easier by using the else function.
Thanks a lot I appreciate your help.
// untested code
#define onPause 5000
#define offPause 9000
long lastRun = 0;
...
void loop() {
if ((digitalRead(ledPin) == LOW) && (millis() - lastRun > offPause)) {
// LED has been off for at least or longer than offPause, turn it on
digitalWrite(ledPin, HIGH);
lastRun = millis();
}
if ((digitalRead(ledPin) == HIGH) && (millis() - lastRun > onPause)) {
// LED has been on for at least or longer then onPause, turn it off
digitalWrite(ledPin, LOW);
lastRun = millis();
}
}
In my code repository (link below) there is a Multiblink example that uses a data table to define many LEDs at different frequencies and time intervals. The code is a bit complex, as it allows for very general things to happen, but you may be able to learn from it (or play with the LED patterns).