-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWasher.ino
223 lines (204 loc) · 6.01 KB
/
Washer.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//Fill in the values below with the pins that you chose to use
#include <Arduino.h>
#include <Wire.h>
const int POT_PIN = A0 ;
const int BUTTON_PIN = 2 ;
const int HOT_PIN = 4 ;
const int COLD_PIN = 9;
const int DRY_PIN = 8;
const int LOCK_PIN = 13;
enum State {
idle,
ecold,
edry,
dhot,
ddry,
sdhot,
sdmedium,
sddry,
};
State counterState = idle; //What state are we currently in?
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP); //let the button be the INPUT_PULLUP
pinMode(POT_PIN, INPUT); //let the pot be an INPUT
pinMode(LOCK_PIN,OUTPUT); //let lock_pin be the output //turn on lock light
pinMode(COLD_PIN,OUTPUT);
pinMode(HOT_PIN,OUTPUT);
pinMode(DRY_PIN,OUTPUT);
}
void loop() {
counterState = determineNextState(counterState);
}
State determineNextState(State currentState)
{
switch (currentState)
{
case idle:
// pinMode(LOCK_PIN,OUTPUT); //let lock_pin be the output
digitalWrite(LOCK_PIN, LOW); //turn on lock light
// pinMode(COLD_PIN,OUTPUT);
digitalWrite(COLD_PIN,LOW);
// pinMode(HOT_PIN,OUTPUT);
digitalWrite(HOT_PIN,LOW);
// pinMode(DRY_PIN,OUTPUT);
digitalWrite(DRY_PIN,LOW);
if(digitalRead(BUTTON_PIN) == LOW)
{
if(analogRead(POT_PIN) >= 1000)
{
pprint(currentState);
currentState = ecold;
}
else if(analogRead(POT_PIN) >= 510 && analogRead(POT_PIN) <= 530)
{
pprint(currentState);
currentState = dhot;
}
else if(analogRead(POT_PIN) <= 10)
{
pprint(currentState);
currentState = sdhot;
}
}
else
{
pprint(currentState);
currentState = idle;
}
break;
case ecold:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(COLD_PIN,OUTPUT);
digitalWrite(COLD_PIN,HIGH);
delay(5000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(COLD_PIN, LOW);
if(analogRead(POT_PIN) <= 10) //if the pot is switched to supper deluxe
{
pprint(currentState);
currentState = sddry;
}
else if(analogRead(POT_PIN) >= 510 && analogRead(POT_PIN) <= 530) //if the pot is switched to deluxe
{
pprint(currentState);
currentState = ddry;
}
else //proceed to economical dry state if the pot is not switched to other modes
{
pprint(currentState);
currentState = edry;
}
break;
case edry:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(DRY_PIN,OUTPUT);
digitalWrite(DRY_PIN,HIGH);
delay(2000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(DRY_PIN, LOW);
pprint(currentState);
currentState = idle;
break;
// }
// else if(analogRead(POT_PIN) >= 510 && analogRead(POT_PIN) <= 530) //if the pot is in the deluxe mode
// {
case dhot:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(HOT_PIN,OUTPUT);
digitalWrite(HOT_PIN,HIGH);
delay(7000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(HOT_PIN, LOW);
if(analogRead(POT_PIN) >= 1000) //if the pot is switched to econ mode
{
pprint(currentState);
currentState = edry;
}
else //proceed to deluxe dry state because if the pot is switched to super deluxe mode, the deluxe dry state is the same as the super deluxe dry state
{
pprint(currentState);
currentState = ddry;
}
break;
case ddry:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(DRY_PIN,OUTPUT);
digitalWrite(DRY_PIN,HIGH);
delay(7000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(DRY_PIN, LOW);
pprint(currentState);
currentState = idle;
break;
// }
// else if(analogRead(POT_PIN) <= 10) //
// {
case sdhot:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(HOT_PIN,OUTPUT);
digitalWrite(HOT_PIN,HIGH);
delay(7000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(HOT_PIN, LOW);
if(analogRead(POT_PIN) >= 1000)
{
pprint(currentState);
currentState = edry;
}
else
{
pprint(currentState);
currentState = sdmedium;
}
break;
case sdmedium:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(HOT_PIN,OUTPUT);
digitalWrite(HOT_PIN,HIGH);
// pinMode(COLD_PIN, OUTPUT);
digitalWrite(COLD_PIN,HIGH);
delay(7000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(HOT_PIN, LOW);
digitalWrite(COLD_PIN, LOW);
if(analogRead(POT_PIN) >= 1000)
{
pprint(currentState);
currentState = edry;
}
else
{
pprint(currentState);
currentState = sddry;
}
break;
case sddry:
// pinMode(LOCK_PIN,OUTPUT);
digitalWrite(LOCK_PIN, HIGH);
// pinMode(DRY_PIN,OUTPUT);
digitalWrite(DRY_PIN,HIGH);
delay(7000);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(DRY_PIN, LOW);
pprint(currentState);
currentState = idle;
break;
// }
// }
// else
// {
// pprint(currentState);
// currentState = idle;
}
return currentState;
}
void pprint(State stateToPrint) {
Serial.print(stateToPrint);
}