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