-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_oct26a.ino
56 lines (45 loc) · 1.53 KB
/
sketch_oct26a.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
int led_verifica[] = {39, 38};
int leds[] = {45, 40};
void setup() {
pinMode(34, OUTPUT);
pinMode(30, OUTPUT);
int leds_len = sizeof(leds)/sizeof(leds[0]);
for(int i = 0; i < leds_len; i++) {
pinMode(leds[i], OUTPUT);
pinMode(led_verifica[i], INPUT);
digitalWrite(leds[i], HIGH);
}
Serial.begin(9600);
Serial1.begin(9600);
}
String stato_led_prima = "collegato";
void loop() {
if(Serial1.available()) {
Serial.println(Serial1.read());
}
int stato_led = 0;
int led_verifica_len = sizeof(led_verifica)/sizeof(led_verifica[0]);
for(int i = 0; i < led_verifica_len; i++) {
if (digitalRead(led_verifica[i])) {
stato_led = digitalRead(led_verifica[i]);
Serial.println(stato_led);
if (stato_led == 1 && stato_led_prima == "collegato") {
Serial.println("Scollegato");
Serial.println((String)"Led "+leds[i]+": "+stato_led);
digitalWrite(34, HIGH);
delay(300);
Serial1.println((String)"Led_"+leds[i]+"_"+stato_led+"_"+stato_led_prima);
stato_led_prima = "scollegato";
} else if(stato_led == 1 && stato_led_prima == "scollegato") {
Serial.println("Collegato");
Serial.println((String)"Led "+leds[i]+": "+stato_led);
digitalWrite(34, HIGH);
delay(300);
Serial1.println((String)"Led_"+leds[i]+"_"+stato_led+"_"+stato_led_prima);
stato_led_prima = "collegato";
}
} else {
digitalWrite(34, LOW);
}
}
}