-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.ino
More file actions
159 lines (139 loc) · 5.23 KB
/
basic.ino
File metadata and controls
159 lines (139 loc) · 5.23 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
int input = 0;
int currentMode = -1;
int switchDelay = 200; //time needed to turn the valve ON/OFF in milliseconds
bool showMenue = true;
bool runOnce = false;
void setup() {
pinMode(5, OUTPUT); // digitalPin #1
pinMode(4, OUTPUT); // digitalPin #2
pinMode(0, OUTPUT); // digitalPin #3
pinMode(2, OUTPUT); // digitalPin #4
digitalWrite(5, LOW); //complementary to
digitalWrite(4, LOW); //complementary to
digitalWrite(0, LOW);
digitalWrite(2, LOW);
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect
}
Serial.println();
Serial.println();
Serial.println("!Please switch 'NL' and 'CR' OFF!");
Serial.println();
drawMenue();
}
void drawMenue(){
Serial.println("**************************************************************");
Serial.println("* Please select desired action from the list below: *");
Serial.println("**************************************************************");
Serial.println("* 1: Press '1' and 'Enter' to close first valve; *");
Serial.println("**************************************************************");
Serial.println("* 2: Press '2' and 'Enter' to open first valve; *");
Serial.println("**************************************************************");
Serial.println("* 3: Press '3' and 'Enter' to close second valve; *");
Serial.println("**************************************************************");
Serial.println("* 4: Press '4' and 'Enter' to open second valve; *");
Serial.println("**************************************************************");
Serial.println("* 5: Press '5' and 'Enter' to view leakage sensor value; *");
Serial.println("**************************************************************");
Serial.println("* Press '0' and 'Enter' to draw this menue; *");
Serial.println("**************************************************************");
showMenue = false;
}
void switchCycle(){
switch(currentMode){
case 0:
Serial.println();
Serial.println("!Please switch 'NL' and 'CR' OFF!");
Serial.println();
runOnce = false;
showMenue = true;
break;
case 1:
digitalWrite(2, HIGH); // first valve closed
digitalWrite(0, HIGH); // powerUp first switch
Serial.println("**************************************************************");
Serial.println("* FIRST VALVE CLOSED! *");
Serial.println("**************************************************************");
currentMode = -1;
runOnce = false;
showMenue = true;
delay(switchDelay);
digitalWrite(0, LOW); // powerDown first switch
break;
case 2:
digitalWrite(2, LOW); // first valve open
digitalWrite(0, HIGH); // powerUp first switch
delay(switchDelay);
digitalWrite(0, LOW); // powerDown first switch
Serial.println("**************************************************************");
Serial.println("* FIRST VALVE OPENED! *");
Serial.println("**************************************************************");
currentMode = 0;
runOnce = false;
showMenue = true;
break;
case 3:
digitalWrite(5, HIGH); // second valve closed
digitalWrite(4, HIGH); // powerUp second switch
delay(switchDelay);
digitalWrite(4, LOW); // powerDown second switch
Serial.println("**************************************************************");
Serial.println("* SECOND VALVE CLOSED! *");
Serial.println("**************************************************************");
currentMode = -1;
runOnce = false;
showMenue = true;
break;
case 4:
digitalWrite(5, LOW); // second valve open
digitalWrite(4, HIGH); // powerUp second switch
delay(switchDelay);
digitalWrite(4, LOW); // powerDown second switch
Serial.println("**************************************************************");
Serial.println("* SECOND VALVE OPENED! *");
Serial.println("**************************************************************");
currentMode = -1;
runOnce = false;
showMenue = true;
break;
case 5:
int sensorValue = analogRead(A0);
Serial.println("**************************************************************");
Serial.print("Current leakage sensor value: ");Serial.println(sensorValue);
Serial.println("**************************************************************");
currentMode = -1;
runOnce = false;
showMenue = true;
break;
}
}
void getInput(){
if(Serial.available() >0){
runOnce = true;
}
if(runOnce){
while(Serial.available() > 0){
input = Serial.parseInt();
Serial.print("Your input is: ");
Serial.println(input);
}
if(input>5 || input<0){
Serial.println("**************************************************************");
Serial.println("* WRONG INPUT! Please enter value from 1 to 5 *");
Serial.println("**************************************************************");
runOnce = false;
showMenue = true;
}
if(input<6 && input>-1){
currentMode = input;
}
switchCycle();
}
}
void loop() {
getInput();
if(showMenue){
drawMenue();
}
}