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.
Then add three variables, Red, Green, and Blue.
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:
- Set the LED to 15.
- Create a Forever loop.
- Set the variable Green to power level 0.
- REPEAT 30
- Use Set_Color to adjust the power level of Green
- Increase the power level by 8.
- Wait a moment and then repeat.
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.
If the LED number is incremented by one each time, a row of LEDs fading from red to green is created.