]> git.piffa.net Git - sketchbook_andrea/blob - RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino
b9fb9521e430e9d1db11fc06787257c66ae4f052
[sketchbook_andrea] / RGB_LED / rgb_0_soluzione / rgb_0_soluzione.ino
1 /*
2     Adafruit Arduino - Lesson 3. RGB LED
3  
4  RGB LED: mpostare i colori per un LED RGB
5  common anode
6  */
7
8 int redPin = 11;
9 int greenPin = 10;
10 int bluePin = 9;
11
12
13
14 void setup()
15 {
16   pinMode(redPin, OUTPUT);
17   pinMode(greenPin, OUTPUT);
18   pinMode(bluePin, OUTPUT);
19 }
20
21 void loop()
22 {
23   setColor(255,0,0) ; // imposta il LED in rosso
24   //setColor(0xFF,0x00,0x00) ; // imposta il LED in rosso in esadecimale
25
26   // setName("green") ; 
27 }
28
29 // Funzioni:
30 void setColor(int red, int green, int blue)
31 // Imposta i colori di un LED RGB Common Anodote
32 // in esadecimale
33 {
34   analogWrite(redPin, 255 -red);
35   analogWrite(greenPin, 255 - green);
36   analogWrite(bluePin, 255 - blue);
37 }
38
39 void setName(String colorName)
40 // Imposta i colori di un LED RGB Common Anodote
41 // tramite una stringa
42 {
43   if (colorName == "red") {
44     analogWrite(redPin, 0 );
45     analogWrite(greenPin, 255 );
46     analogWrite(bluePin, 255 );
47   } 
48   else if (colorName == "green") {
49     analogWrite(redPin, 255 );
50     analogWrite(greenPin, 0 );
51     analogWrite(bluePin, 255 );
52   }
53   // ...
54 }
55 /* Hints:
56
57 1. Per usare un solo valore esadecimale per settare i colori:
58    - http://ardx.org/src/code/CIRC12-code-MB-SPAR.txt
59  
60  */
61
62
63
64
65
66
67