Created
April 4, 2014 02:28
-
-
Save nataliefreed/9966951 to your computer and use it in GitHub Desktop.
RGB Color-Mixing LED example code for LilyPad ProtoSnap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//RGB Color-Mixing LED | |
//For LilyPad ProtoSnap | |
/************************************* | |
//Change the variables in this section | |
//Colors are between 0 and 255 | |
//Times are in milliseconds. For eg., 1 second = 1000 milliseconds. | |
*************************************/ | |
int colors[][3] = { {255, 150, 0}, {100, 0, 200}, {255, 0, 0}}; | |
int times[] = { 5000, 1000, 500 }; | |
int numberOfColors = 3; | |
/************************************* | |
end of section | |
*************************************/ | |
int red = 9; | |
int blue = 10; | |
int green = 11; | |
int counter = 0; | |
long timer; | |
void setup() | |
{ | |
pinMode(red, OUTPUT); | |
pinMode(green, OUTPUT); | |
pinMode(blue, OUTPUT); | |
digitalWrite(red, HIGH); | |
digitalWrite(green, HIGH); | |
digitalWrite(blue, HIGH); | |
timer = millis(); | |
setColor(colors[0][0], colors[0][1], colors[0][2]); | |
} | |
void loop() | |
{ | |
if(millis() - timer > times[counter]) | |
{ | |
counter = (counter + 1) % numberOfColors; | |
setColor(colors[counter][0], colors[counter][1], colors[counter][2]); | |
timer = millis(); | |
} | |
} | |
void setColor(int r, int g, int b) | |
{ | |
analogWrite(red, map(r, 0, 255, 255, 0)); | |
analogWrite(green, map(g, 0, 255, 255, 0)); | |
analogWrite(blue, map(b, 0, 255, 255, 0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment