Skip to content

Instantly share code, notes, and snippets.

@mcantelon
Created September 1, 2010 03:22
Show Gist options
  • Save mcantelon/560175 to your computer and use it in GitHub Desktop.
Save mcantelon/560175 to your computer and use it in GitHub Desktop.
/*
* face through RGB
*/
int ledPin = 13; // LED is connected to digital pin 13
int redPin = 11; // R petal on RGB LED module connected to digital pin 11
int greenPin = 9; // G petal on RGB LED module connected to digital pin 9
int bluePin = 10; // B petal on RGB LED module connected to digital pin 10
int wait = 5; // delay between color changes
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
}
void loop() // run over and over again
{
for (int g = 0; g < 255; g++) {
color(255, g, 0);
delay(wait);
}
for (int b = 0; b < 255; b++) {
color(255, 255, b);
delay(wait);
}
for (int r = 255; r > 0; r--) {
color(r, 255, 255);
delay(wait);
}
for (int g = 255; g > 0; g--) {
color(0, g, 255);
delay(wait);
}
int r = 0;
for (int b = 255; b > 0; b--) {
color(r, 0, b);
r++;
delay(wait);
}
}
void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, 255-red);
analogWrite(bluePin, 255-blue);
analogWrite(greenPin, 255-green);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment