X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=RGB_LED%2Frgb_1_all_color%2Frgb_1_all_color.ino;h=a53a02ab34ba036a95f846514e82b1c6328145ab;hb=6546e84b197a1c8e33b4bbd206dd4d31c664d99b;hp=29969add229ffc2368a934e61a4c4cb41ba5a7da;hpb=54de1d245a98a8032e8c41089158321f6be58b1c;p=sketchbook_andrea diff --git a/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino b/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino index 29969ad..a53a02a 100644 --- a/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino +++ b/RGB_LED/rgb_1_all_color/rgb_1_all_color.ino @@ -1,45 +1,54 @@ - /* +/* Adafruit Arduino - Lesson 3. RGB LED - */ - - int redPin = 11; - int greenPin = 10; - int bluePin = 9; - - //uncomment this line if using a Common Anode LED - //#define COMMON_ANODE - - void setup() - { - pinMode(redPin, OUTPUT); - pinMode(greenPin, OUTPUT); - pinMode(bluePin, OUTPUT); - } - - void loop() - { - setColor(255, 0, 0); // red - delay(1000); - setColor(0, 255, 0); // green - delay(1000); - setColor(0, 0, 255); // blue - delay(1000); - setColor(255, 255, 0); // yellow - delay(1000); - setColor(80, 0, 80); // purple - delay(1000); - setColor(0, 255, 255); // aqua - delay(1000); - } - - void setColor(int red, int green, int blue) - { - #ifdef COMMON_ANODE - red = 255 - red; - green = 255 - green; - blue = 255 - blue; - #endif - analogWrite(redPin, red); - analogWrite(greenPin, green); - analogWrite(bluePin, blue); - } + + RGB LED: rotazione tra tutti i colori. + + Schema: http://lab.piffa.net/schemi/rgb.jpg + + */ + +int redPin = 11; +int greenPin = 10; +int bluePin = 9; + +//uncomment this line if using a Common Anode LED +#define COMMON_ANODE + +void setup() +{ + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(bluePin, OUTPUT); +} + +void loop() +{ + setColor(255, 0, 0); // red + delay(1000); + setColor(0, 255, 0); // green + delay(1000); + setColor(0, 0, 255); // blue + delay(1000); + setColor(255, 255, 0); // yellow + delay(1000); + setColor(80, 0, 80); // purple + delay(1000); + setColor(0, 255, 255); // aqua + delay(1000); +} + +void setColor(int red, int green, int blue) +{ +#ifdef COMMON_ANODE + red = 255 - red; + green = 255 - green; + blue = 255 - blue; +#endif + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); +} + + + +