-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprinkler_system.ino
71 lines (59 loc) · 1.23 KB
/
sprinkler_system.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//pin Arduino I/O
const int sensorpin = 11;
const int ledpin = 7;
const int buzzerpin = 3;
const int fumopin = 5;
//Variabili
int statofiamma = 0;
int statofumo = 0;
double temperatura{};
double val{};
//Stato
int stato = 1;
void setup()
{
pinMode(sensorpin,INPUT);
pinMode(ledpin,OUTPUT);
pinMode(buzzerpin, OUTPUT);
pinMode(fumopin, INPUT);
Serial.begin(9600);
}
void loop()
{
state_loop(stato);
}
void state_loop(int& state) //Stato parametrizzato
{
Serial.println("Stato fumo:");
Serial.println (statofumo);
Serial.println("Stato fiamma:");
Serial.println (statofiamma);
statofumo = digitalRead(fumopin);
statofiamma = digitalRead(sensorpin);
temperatura = ((analogRead(A2) * (5.0/1024))-0.5)/0.01;
if (state == 1){
digitalWrite(ledpin,LOW);
}
if (state == 2){
digitalWrite(ledpin,HIGH);
}
if (state == 3){
digitalWrite(ledpin,HIGH);
inter_buzz();
}
if (state == 4{
digitalWrite(ledpin,HIGH);
cont_buzz();
}
state = statofiamma?4:statofumo?3:temperatura>3000?2:1;
}
void inter_buzz()
{
tone(buzzerpin,400,200);
delay (300);
tone(buzzerpin,400,200);
}
void cont_buzz()
{
tone(buzzerpin,400,5000);
}