Devices & Components
Arduino LilyPad Main Board
RGB Diffused Common Cathode
Jumper wires (generic)
Hardware & Tools
Hot glue gun (generic)
Software & Tools
Arduino IDE
Project description
Code
RGB Code
arduino
Uses different methods to change the color of the LEDs.
1int red = 11; 2int green = 9; 3int blue = 5; 4void setup() { 5 pinMode(red,OUTPUT); 6 pinMode(green,OUTPUT); 7 pinMode(blue,OUTPUT); 8} 9 10void loop() { 11/*the different delays in fade and strobe allows for fast and slow iterations*/ 12 fade(2); 13 fade(2); 14 fade(2); 15 strobe(300); 16 strobe(300); 17 strobe(300); 18 fade(10); 19 strobe(100); 20 strobe(100); 21 strobe(100); 22 strobe(100); 23 strobe(100); 24} 25 26void off() 27{ 28 rLight(0); 29 gLight(0); 30 bLight(0); 31} 32 33void strobe(int strobeDelay) 34{ 35 showRGB(255,255,255);//white 36 delay(strobeDelay); 37 showRGB(0,255,255);//cyan 38 delay(strobeDelay); 39 showRGB(255,0,255);//purple 40 delay(strobeDelay); 41 showRGB(255,255,0);//yellow 42 delay(strobeDelay); 43 showRGB(0,0,255);//blue 44 delay(strobeDelay); 45 showRGB(0,255,0);//green 46 delay(strobeDelay); 47 showRGB(255,0,0);//red 48 delay(strobeDelay); 49} 50 51void fade(int fadeDelay) 52{ 53 int r = 255; 54 int g = 0; 55 int b = 0; 56 for(; b<=255;b++){ 57 showRGB(r,g,b); 58 delay(fadeDelay * 3); 59/*the delay is multiplied by different factors because the red portions appear quicker than just blue and green because red appears so much dimmer*/ 60 } 61 for(; r>=0; r--){ 62 showRGB(r,g,b); 63 delay(fadeDelay * 2); 64 } 65 for(; g<=255; g++){ 66 showRGB(r,g,b); 67 delay(fadeDelay); 68 } 69 for(; b>=0; b--){ 70 showRGB(r,g,b); 71 delay(fadeDelay); 72 } 73 for(;r<=255;r++){ 74 showRGB(r,g,b); 75 delay(fadeDelay * 2); 76 } 77 for(;g>=0;g--){ 78 showRGB(r,g,b); 79 delay(fadeDelay * 3); 80 } 81} 82 83void showRGB(int r, int g, int b){ 84 rLight(r); 85 gLight(g); 86 bLight(b); 87} 88 89void rLight(int r){ 90 if(r>=0 && r<=255) 91 analogWrite(red, r); 92} 93 94void gLight(int g){ 95 if(g>=0 && g<=255) 96 analogWrite(green, g); 97} 98 99void bLight(int b){ 100 if(b>=0 && b<=255) 101 analogWrite(blue, b); 102} 103
Downloadable files
Schematic
Schematic
Schematic
Schematic
Comments
Only logged in users can leave comments