Create a new function to control color, Set_Color with three inputs, “R” (for red), “G” (for green), and “B” (for blue). Place the LED variable in the position that specifies the LED number.

The Set_Color Function

Then add three variables, Red, Green, and Blue.

The Red, Green, and Blue Variables

Then create a program that gradually fades an LED on. Rather, than going immediately to full intensity, the program will turn on the power in small increments, creating the fade effect:

  1. Set the LED to 15.
  2. Create a Forever loop.
    1. Set the variable Green to power level 0.
    1. REPEAT 30
      1. Use Set_Color to adjust the power level of Green
      1. Increase the power level by 8.
      1. Wait a moment and then repeat.
Creating a “Fade” Function

Changing the power level in increments of 8 changes the power level of the green LED from 0 to 240 in 30 steps. By adding another color to the mix, the program can cross-fade from one color to another. In this instance, as the power level of the green LED is increased, the power level of the red LED is simultaneously decreased. This causes the LED to fade from red to orange to yellow to green.

Cross-fading from One Color to Another

If the LED number is incremented by one each time, a row of LEDs fading from red to green is created.

Cross-fading from One Color to Another