4 leds blink subsequently

hi, we are having a bit of trouble with our project so could you guys please help us? how do you make 4 leds blink subsequently with a pause in-between without using delay!!!!

thank you

FRED & GIJS

Have you tried modifying the Blink Without Delay example?

There are a couple of different approaches...

The best solution is probably to make the output port a variable and make a looping sequence where a different LED is addressed every time through the loop (starting over after the 4th LED).

Another approach would be to make different previousMillis variables for each LED (previousMillis1, previousMillis2, etc.) And, you might need different on interval & off interval variables.

But how do you modify blink without delay because we tried that but we didn't know how.

But how do you modify blink without delay because we tried that but we didn't know how.

Hi,

What are the problems (to "modify blink without delay") ypu have exactly?

Regards

Indeed, what have you tried? What was the effect? Etc. It's kind of basic so you can ask us for help but you have to do some work as well.

fredengijs: But how do you modify blink without delay because we tried that but we didn't know how.

I am not writing code for you, but using plain english to describe what the code would be like it follows blink without delay is a similar fashion, but not exact. blink without delay is a shell game. three shells. ------------ first ------------------------ you have to have something happen, a switch or just a number or some event. that event has not happened before, but did happen now. that means your first threshold has been crossed. if it happened now if it did not happen before bingo! bingo is where you set then=millis()

=======================================

now at this point you need to put in a line that

before = now

say it was a switch. switch was open but at this scan it has closed.

on the next scan, you need to have the current state of the switch loaded into the value of 'before'

so, you write before = now

oldState = currentState // or some such. before = now // works

from this point on, the old state of the switch is equal to the state of the switch on the last scan. this means that "before" will always be one scan behind.

using our switch example, it was open,open,open,open.... scan after scan before = now means both before and now are = open.....

someone flips the switch, before would still hold the value of open but the current state would be closed.

open,open,open,closed,closed,...... // this would be the state of the switch open,open,open,open,closed,...... // before - it is one scan behind. this separation is our trigger.

back to the first part

if it happened now if it did not happen before bingo! bingo is where you set then=millis()

if switch is closed now{ if the last state of the switch was open { then = millis() } ]

last state = millis() // this has to be on it's own line.

====== part two ===========================

at this point all you did was to create a point in time and set then to that point in time

of course the clock is still ticking, so 'then' happened some time ago. you want to know how long ago.

duration = ( millis()-then ) / this loads that value into duration.

duration is a value that when it reaches 1000 is the same as 1 second., counts in ms. or 1/1000 of a second.

------------ part three ----------------

there is a very real chance that it will go from 998 to 1003 because of something in the program

you want to have some thing with timing.

if duration > 1000 do something.

not if duration = 1000 because it might skip over that value.

this is kool,. but it will always be either over or or under 1000, so once you do something, you will have it done forever, unless you turn it off.

if duration > 1000 and less than 2000 do something

if duration > 2000 stop doing that

you would have the switch change state, * wait 1 second * do something * wait 1 second * stop doing that.

================================

at this point you could write lots and lots of timing things after 2 sec, do a something after 3 stop after 4 do it again or do a third thing after 5 stop.......

would get boring and waste a lot of code to do that to make a single thing blink. but it could be used to blink more than one thing.

after that last thing you could re-set duration

if duration > 5 seconds duration = millis()

this would re-set it to zero and start all over again.

since you set things in motion, it would never stop blinking unless you did something to stop it.

===========================

blink without delay is a concept more than a program. you have to understand that it is not a one-size fits all loop

this example could have you write the start and stop times for multiple things and have it repeat. maybe like a traffic light.

I create 'duration' as my version of blink without delay as it has fit my needs. it is different from the example, but it can work for some applications.

also, you have to write all the IF statements and all the digitalWrite lines and such.

my hope is that this makes sense and you learned how to get this version of blink without delay to work for you.