]> git.piffa.net Git - sketchbook_andrea/blob - RGB_LED/rgb_all_color/rgb_all_color.ino
light and sound
[sketchbook_andrea] / RGB_LED / rgb_all_color / rgb_all_color.ino
1     /*
2     Adafruit Arduino - Lesson 3. RGB LED
3     */
4      
5     int redPin = 11;
6     int greenPin = 10;
7     int bluePin = 9;
8      
9     //uncomment this line if using a Common Anode LED
10     //#define COMMON_ANODE
11      
12     void setup()
13     {
14     pinMode(redPin, OUTPUT);
15     pinMode(greenPin, OUTPUT);
16     pinMode(bluePin, OUTPUT);
17     }
18      
19     void loop()
20     {
21     setColor(255, 0, 0); // red
22     delay(1000);
23     setColor(0, 255, 0); // green
24     delay(1000);
25     setColor(0, 0, 255); // blue
26     delay(1000);
27     setColor(255, 255, 0); // yellow
28     delay(1000);
29     setColor(80, 0, 80); // purple
30     delay(1000);
31     setColor(0, 255, 255); // aqua
32     delay(1000);
33     }
34      
35     void setColor(int red, int green, int blue)
36     {
37     #ifdef COMMON_ANODE
38     red = 255 - red;
39     green = 255 - green;
40     blue = 255 - blue;
41     #endif
42     analogWrite(redPin, red);
43     analogWrite(greenPin, green);
44     analogWrite(bluePin, blue);
45     }