Traffic Light
The basic capabilities for controlling the color of the LED’s can be used to simulate a traffic light. The colors green, yellow, and red can be defined for the simulation. Yellow is a mix of red and green.

Once the functions to produce these three colors have been defined, the traffic light simulation can be written in the following way:
- Turn on the green light.
- Wait a second.
- Turn on the yellow light.
- Wait a second.
- Turn on the red light.
- Wait a second.
The function defined in Figure 28 cycles through green, yellow, and red on a single LED (i.e., LED 1).

With minor adjustments, LED 1 can be defined as the green light, LED 2 can be defined as the yellow light, and LED 3 can be defined as the red light.

This adjustment turns on all three LEDs simultaneously.

An actual traffic light would turn off the green light before turning on the yellow light, etc. To incorporate this behavior into the simulation, a function to turn off each light is needed. This can be accomplished by setting the power levels of the red, green, and blue LEDs to 0. A quirk of the WS2812B LED strip is that the LED must be briefly turned on immediately before setting the power levels to 0 in order to turn off the light. The function Turn_of_LED is shown below.

The revised procedure turns off each light before turning on the next light.
- Turn on the green light (LED 1).
- Wait a second.
- Turn off the green light.
—————————————– - Turn on the yellow light (LED 2).
- Wait a second.
- Turn off the yellow light.
—————————————– - Turn on the red light (LED 3).
- Wait a second.
- Turn off the red light

This process can repeated an infinite number of times by placing it in a Forever loop.

This final version emulates an actual traffic light for use in a diorama or model train layout.