My first Arduino project (after the compulsory Blink, of course). This is a simulated traffic light, with an “Error” switch that blinks the yellow light while it is pressed and resets the light sequence.
The light sequence is actually an array of structs (records), each containing an int with the desired light combination: 4 (100 in binary) for Red only, 2 (010) for yellow only, 1 (001) for Green only, 0 (000) for none – and 6 (110) for Red and Yellow simultaneously. Each struct also contains the number of milliseconds its light combination should stay on before moving on to the next.
I did not use the delay() function, because I had to keep listening to the switch input in “real time”. Instead, I counted milliseconds with the millis() function. While the switch is pressed, I run a similar but simpler light sequence: yellow-none-yellow-none…
(I should probably note that I have programming background, right?)
Thanks to the makers of this awesome hardware and to the good folks that make introductory articles and videos. Happy prototyping!
P.S. Only now, of course, did I realize there are tons of other Arduino traffic lights around 🙂
Duration : 0:1:19