I’m wanting to blink two LEDs independently of one another:
LED 1: on = 801 milliseconds, off = 709 milliseconds
LED 2: on = 709 milliseconds, off = 801 milliseconds
They start off seeming to be synchronised, and slowly as time progresses they separate from one another, and then after a while they synchronise again… and then separate… then synchronise… ad infinitum.
I agree with both other comments on here, but. I can only say one thing: Delay times!!
for example, the IDE example "blink". the code itself contains delay time, which can be adjusted to make it go faster or slower, but what I think you are looking for is something like a police lights effect?
which can be found here:
ofcourse you can adjust both the circuit and code to your liking!
I’m finding the blink without delay code quite complicated to understand – where to put the times for how long it should be off and on for – (the video seems like it might be helpful, but I will need to watch it many more times to understand it). I'll keep with it - at least just for future projects.
I’m finding the blink without delay code quite complicated to understand
It has about four significant lines of code.
unsigned long currentMillis = millis(); // get the current time.
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis; // save the last time you blinked the LED
if (ledState == LOW) // if the LED is off turn it on and vice-versa:
// do something
One important thing to note is that as it stands, it is capable of flashing only one LED, but because "interval" is a variable, when you change the state of the LED, you could also change the on or off time too.
(one other thing currentMillis - previousMillis > interval should be currentMillis - previousMillis >= interval
.... all use LedFlasher() which is a function created inside LedFlasher.h, and the include makes that function available to you. It wouldn't surprise me in the slightest if Nick's LedFlasher internally used state machines to do the work. So I'm pretty sure, Nick's approach will be similar to the video, but insulating you from the drudge by bringing it to you in an include.
I have a MultiBlink sketch at my code repository (link below) that should do what you need, including effects like police lights, just by changing the parameter data at the top of the sketch.