I picked up my first Arduino and I am impressed with it's capabilities. Just thought I'd share my first sketch. It uses the common annode, full color LED, Radio Shack model # 276-028. I used three PWM outputs to fade out each of the 7 basic color combination that can be made with the RGB LED. I am sure this code could be done simpler but I had so much fun getting it to work so easily! I can't wait to think up more things to make!
// RGB 7 Color Fade Out Looper
// By: CLM3S
// Define LED Color Pin Outputs
int RedPin = 11;
int GreenPin = 10;
int BluePin = 9;
void setup()
{
}
void loop()
{
// Fade Out Red
for (int x=0; x<256; x=x+5) {
analogWrite (RedPin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
// Fade Out Green
for (int x=0; x<256; x=x+5) {
analogWrite (GreenPin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
// Fade Out Blue
for (int x=0; x<256; x=x+5) {
analogWrite (BluePin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
// Fade Out Cyan
for (int x=0; x<256; x=x+5) {
analogWrite (GreenPin, x);
analogWrite (BluePin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
// Fade Out Yellow
for (int x=0; x<256; x=x+5) {
analogWrite (RedPin, x);
analogWrite (GreenPin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
// Fade Out Magenta
for (int x=0; x<256; x=x+5) {
analogWrite (RedPin, x);
analogWrite (BluePin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
// Fade Out White
for (int x=0; x<256; x=x+5) {
analogWrite (RedPin, (x / 2) + (256 - (256 / 2)));
analogWrite (GreenPin, x);
analogWrite (BluePin, x);
delay(10);
}
// Clear All Colors
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
delay(25);
}
Enjoy!