EricLathrop.com
Arduino RGB LED Color Blending
I recently purchased an Ardunio Starter pack from adafruit.com to begin learning microcontroller programming. Adafruit has some a great introduction for people new to electronics.
After following the lesson 3 of the Ladyada Arduino tutorial, I extended the code to fade between the colors of the rainbow:
The showColor() function sets the red, green, and blue LEDs to the given values.
The fadeToColor() function will fade from one color to another taking delayMillisec milliseconds to do the fading.
I wired up a pushbutton through a pull-up resistor to create an on/off button.
In the main loop, isRunning() checks the button's input to see if it has been pulled low, and flips a bit on the lead edge of the button press.
If isRunning() returns false, then all the LEDs are turned off.
The main loop() loops through the colors of the rainbow, fading from one to the next.
Download the code as an Arduino sketch released into the public domain.