int redPin = 9; // LED connected to digital pin 9
int greenPin = 10;
int bluePin = 11;
void fadeIn(int pin, int fadeInc, int delayValue)
{
for (int fadeValue = 0; fadeValue<= 255; fadeValue += fadeInc)
{
analogWrite(pin, fadeValue);
delay(delayValue);
}
}
// fade out from max to min in increments
void fadeOut(int pin, int fadeInc, int delayValue)
{
for (int fadeValue = 255; fadeValue >= 0; fadeValue -= fadeInc)
{
analogWrite(pin, fadeValue);
delay(delayValue);
}
}
void rgb (int r, int g, int b)
{
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);
delay(30);
}
void setup() {
Serial.begin(9600);
// diagnostic lights on
fadeIn(redPin, 5, 60);
fadeOut(redPin, 5, 60);
analogWrite(redPin, 0);
delay(30);
fadeIn(greenPin, 5, 60);
fadeOut(greenPin, 5, 60);
analogWrite(greenPin, 0);
delay(30);
fadeIn(bluePin, 5, 60);
fadeOut(bluePin, 5, 60);
analogWrite(bluePin, 0);
delay(30);
Serial.print(redPin);
Serial.print(", ");
Serial.print(greenPin);
Serial.print(", ");
Serial.println(bluePin);
}
void loop() {
for (int r = 0; r <= 255; r++)
{
for (int g = 0; g <= 255; g++)
{
for (int b = 0; b <= 255; b++)
{
rgb(r, g, b);
Serial.print(r);
Serial.print(", ");
Serial.print(g);
Serial.print(", ");
Serial.println(b);
}
}
}
}
Saturday, March 06, 2010
March Madness Challenge - Day 6
Loss of brain power leads to coding RGB LED enumeration for Arduino. Tired going to bed soon.
Subscribe to:
Post Comments (Atom)
3 comments:
We need a video of this running to see how well the transitions work. I know I saw it at the class yesterday but still, you should share!
OK. I'll get it together. It's more diagnostic than pretty.
The above code had a couple of cut, paste coding errors. It's also still not good code. I'll want to come back to this and clean it up. It does stuff but is not satisfying.
Post a Comment