1int SENSOR=A0;
2int LEDverde=7;
3int LEDrosso=8;
4int LEDrgb1_red=3;
5int LEDrgb1_green=5;
6int LEDrgb1_blue=6;
7int LEDrgb2_red=9;
8int LEDrgb2_green=10;
9int LEDrgb2_blue=11;
10int LEDbianco=4;
11int LEDblu=12;
12int val = 0;
13int ledn =0;
14
15void setup() {
16 pinMode(LEDverde, OUTPUT);
17 pinMode(LEDrosso, OUTPUT);
18 pinMode(LEDrgb1_red, OUTPUT);
19 pinMode(LEDrgb1_green, OUTPUT);
20 pinMode(LEDrgb1_blue, OUTPUT);
21 pinMode(LEDrgb2_red, OUTPUT);
22 pinMode(LEDrgb2_green, OUTPUT);
23 pinMode(LEDrgb2_blue, OUTPUT);
24 pinMode(LEDbianco, OUTPUT);
25 pinMode(LEDblu, OUTPUT);
26
27 digitalWrite(LEDverde, LOW);
28 digitalWrite(LEDrosso, LOW);
29 digitalWrite(LEDbianco, LOW);
30 digitalWrite(LEDblu, LOW);
31 delay(4000);
32 digitalWrite(LEDverde, HIGH);
33 digitalWrite(LEDrosso, LOW);
34 digitalWrite(LEDbianco, LOW);
35 digitalWrite(LEDblu, LOW);
36
37 delay(5000);
38 digitalWrite(LEDverde, HIGH);
39 digitalWrite(LEDrosso, HIGH);
40 digitalWrite(LEDbianco, LOW);
41 digitalWrite(LEDblu, LOW);
42 delay(7000);
43 digitalWrite(LEDverde, HIGH);
44 digitalWrite(LEDrosso, HIGH);
45 digitalWrite(LEDbianco, HIGH);
46 digitalWrite(LEDblu, LOW);
47 delay(5000);
48 digitalWrite(LEDverde, HIGH);
49 digitalWrite(LEDrosso, HIGH);
50 digitalWrite(LEDbianco, HIGH);
51 digitalWrite(LEDblu, HIGH);
52 delay(6000);
53 digitalWrite(LEDverde, HIGH);
54 digitalWrite(LEDrosso, HIGH);
55 digitalWrite(LEDbianco, HIGH);
56 digitalWrite(LEDblu, HIGH);
57 analogWrite(LEDrgb1_red, 0);
58 analogWrite(LEDrgb1_green, 0);
59 analogWrite(LEDrgb1_blue, 0);
60 analogWrite(LEDrgb2_red, 0);
61 analogWrite(LEDrgb2_green, 0);
62 analogWrite(LEDrgb2_blue, 0);
63
64 }
65
66void loop(){
67 val = analogRead(SENSOR);
68 ledn = (int) round( val / 255.75);
69switch (ledn) {
70
71case 1:
72digitalWrite(LEDverde, HIGH);
73analogWrite(LEDrgb1_red, 0);
74analogWrite(LEDrgb1_green, 255);
75analogWrite(LEDrgb1_blue, 0);
76analogWrite(LEDrgb2_red, 0);
77analogWrite(LEDrgb2_green, 255);
78analogWrite(LEDrgb2_blue, 0);
79digitalWrite(LEDrosso, LOW);
80digitalWrite(LEDblu, LOW);
81digitalWrite(LEDbianco, LOW);
82
83break;
84
85case 2:
86digitalWrite(LEDrosso, HIGH);
87analogWrite(LEDrgb1_red, 255);
88analogWrite(LEDrgb1_green, 0);
89analogWrite(LEDrgb1_blue, 0);
90analogWrite(LEDrgb2_red, 255);
91analogWrite(LEDrgb2_green, 0);
92analogWrite(LEDrgb2_blue, 0);
93digitalWrite(LEDverde, LOW);
94digitalWrite(LEDblu, LOW);
95digitalWrite(LEDbianco, LOW);
96break;
97
98case 3:
99digitalWrite(LEDbianco, HIGH);
100analogWrite(LEDrgb1_red, 255);
101analogWrite(LEDrgb1_green, 255);
102analogWrite(LEDrgb1_blue, 255);
103analogWrite(LEDrgb2_red, 255);
104analogWrite(LEDrgb2_green, 255);
105analogWrite(LEDrgb2_blue, 255);
106digitalWrite(LEDrosso, LOW);
107digitalWrite(LEDblu, LOW);
108digitalWrite(LEDverde, LOW);
109break;
110
111case 4:
112digitalWrite(LEDblu, HIGH);
113analogWrite(LEDrgb1_red, 0);
114analogWrite(LEDrgb1_green, 0);
115analogWrite(LEDrgb1_blue, 255);
116analogWrite(LEDrgb2_red, 0);
117analogWrite(LEDrgb2_green, 0);
118analogWrite(LEDrgb2_blue, 255);
119digitalWrite(LEDrosso, LOW);
120digitalWrite(LEDverde, LOW);
121digitalWrite(LEDbianco, LOW);
122break;
123}
124delay(100);
125}
126