Arduino Traffic Light (Beginner's project)

Опубликовано: 04 Октябрь 2024
на канале: The White Byte
16,978
29

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!

Download the code here: http://www.idogendel.com/whitebyte/so...

Check out the newer toy version here:    • ATTiny85 Toy: Traffic Light and Polic...  

P.S. Only now, of course, did I realize there are tons of other Arduino traffic lights around :-)