Go Down

Topic: Sticky - Blink Two LEDs, independent, no delay (Read 7095 times) previous topic - next topic

Jassper

#75
Nov 21, 2011, 07:00 pm Last Edit: Nov 21, 2011, 07:06 pm by Jassper Reason: 1
This might be a better solution ;) (at least for more complicated issues)

http://www.element14.com/community/message/40256#40256/l/event-driven-state-machine-framework-for-arduino

GoForSmoke


 In changing the title and in writing the explanation keep in mind that the most important concept here is the fact that the code is implementing a 'delay' without using the 'delay()' function.  The fact that one or more LEDs are blinking is not really what this is all about.

The blinking of an LED is an example of what can be done with any kind of delay technique.  The blinking of an LED while also doing something else is an example of what can be done when the use of delay() is eliminated, as is the independent blinking of two LEDs.


It also helps introduce how to handle/work with asynchronous events which to my mind is the crux of loop().

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Msquare

In my mind the reason for this "sticky" was to extend the Blink without delay() tutorial to two LEDs. Thus the explanation of avoiding using delay() is assumed covered. This was to help make the mental leap from the single LED to the general case. (Some people cant even make the leap from a LED to a motor ...)

No, it is not a complete example on the "best" way to blink a LED. No, it wasnt an example on how to implement polled multithread programming.

floresta

Quote
Thus the explanation of avoiding using delay() is assumed covered.

Just make sure that if the word 'delay' is used in the title that it includes the parentheses.  Actually it would probably be better to indicate what is being used rather than what is not being used.  How about 'Blink Two LEDs independently without blocking' or 'Blink Two LEDs independently using millis()' ?

Don

Go Up