[C.CC USERS] 3 Blinkin lights - other solutions
Steve Pretty
steve.g.pretty at btinternet.com
Mon Feb 28 21:38:47 GMT 2011
I tried the three (and 4 and 5!) Blinkin lights myself. It is
fascinating to see the kind of complex issues that can arise in
concurrent code coming up in just three lines of code. Using "Blink" on
three LEDs is causing 18 (at least) occam processes to compete for
processing cycles ( each Blink starts a tick (which starts a delay) and
a pin.toggle (which starts a toggle and a digital.output).
Of course, if you just want three LEDs to flash in syncronism, you might
be best just to use a single timer and distribute the output to three
output functions - e.g.:
#INCLUDE "plumbing.module"
PROC delta3 (CHAN SIGNAL x?, x1!, x2!, x3!)
WHILE TRUE
SEQ
x ? SIGNAL
x1 ! SIGNAL
x2 ! SIGNAL
x3 ! SIGNAL
:
PROC main ()
CHAN SIGNAL s, s1, s2, s3:
PAR
tick (100, s!)
delta3 (s?, s1!, s2!, s3!)
pin.toggle (11, LOW, s1?)
pin.toggle (10, LOW, s2?)
pin.toggle (9, LOW, s3?)
:
All the lights run in synch using this approach. Well - actually, I put
a logic analyser on it - becasue of the concurrency, the LEDs come on
one after another, with the third coming on typically 5ms after the first.
The engineering side of me says that the simplest way to get three LEDS
to blick in sync is to wire them in parallel!
Steve
More information about the users
mailing list