-
Notifications
You must be signed in to change notification settings - Fork 0
/
washerarduino.ino
177 lines (172 loc) · 4.44 KB
/
washerarduino.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
#include <Arduino.h>
#include <Wire.h>
//Fill in the values below with the pins that you chose to use
const int POT_PIN = A0;
const int BUTTON_PIN = 4;
const int HOT_PIN = 6;
const int DRY_PIN = 8;
const int COLD_PIN = 10;
const int LOCK_PIN = 13;
/*
* Pin to press button = 4
* Pin to turn on hot wash = 6 - red LED
* Pin to turn on dry = 8 - yellow LED
* Pin to turn on cold wash = 10 - green LED
* pin to lock the door= 13
* Pin to do the potentiometer = A0
*/
enum State{economy, deluxeWash, superDeluxeWash,idle};
State currentState = idle;
int isPushed = 0;
void setup() {
Serial.begin(9600);
pinMode(HOT_PIN,OUTPUT);
pinMode(COLD_PIN,OUTPUT);
pinMode(DRY_PIN,OUTPUT);
pinMode(LOCK_PIN,OUTPUT);
pinMode(BUTTON_PIN,INPUT_PULLUP);
pinMode(POT_PIN,INPUT);
}
void loop() {
currentState = changeSettings(currentState);
if (int (digitalRead(BUTTON_PIN))==0){
isPushed++;
}
}
State changeSettings(State currentState){
switch (currentState)
{
case idle:
{
//setting all the pins to low
Serial.println("idle state");
delay(3000);
digitalWrite(HOT_PIN,LOW);
digitalWrite(LOCK_PIN,LOW);
digitalWrite(COLD_PIN,LOW);
digitalWrite(DRY_PIN,LOW);
double sensorValue = analogRead(POT_PIN);
//only runs if the button is pressed
//if (int (digitalRead(BUTTON_PIN))==0)
if (isPushed>0)
{
if(sensorValue>=400&&sensorValue<700){
Serial.println("delux");
currentState = deluxeWash;
return currentState;
break;
}
else if (sensorValue<=30){
Serial.println("economy");
currentState = economy;
return currentState;
break;
}
else if (sensorValue>700){
Serial.println("super deluxe");
currentState = superDeluxeWash;
return currentState;
break;
}
else{
Serial.println("idle");
currentState = idle;
return currentState;
break;
}
}
currentState = idle;
return currentState;
break;
}
case economy:
{
//gotta lock the door and then turn on cold wash
digitalWrite(LOCK_PIN,HIGH);
digitalWrite(COLD_PIN,HIGH);
//will run for 5 seconds
delay(5000);
//turn off cold wash and turn on the dryer
digitalWrite(COLD_PIN,LOW);
double sensorValue = analogRead(POT_PIN);
//if voltage is not in economy mode anymore, we will dry for 7 seconds
if(sensorValue>300){
Serial.println("deluxe dry");
digitalWrite(DRY_PIN,HIGH);
delay(7000);
digitalWrite(DRY_PIN,LOW);
currentState = idle;
return currentState;
break;
}
else{
//let dry for a few seconds
Serial.println("economy dry");
digitalWrite(DRY_PIN,HIGH);
delay(2000);
digitalWrite(DRY_PIN,LOW);
}
currentState = idle;
return currentState;
break;
}
case deluxeWash:
{
Serial.println("deluxe wash");
//lock and turn on hot for 7 seconds
digitalWrite(LOCK_PIN,HIGH);
digitalWrite(HOT_PIN,HIGH);
delay(7000);
//turn off the hot water
digitalWrite(HOT_PIN,LOW);
//calculate what the voltage should be
double sensorValue = analogRead(POT_PIN);
if(sensorValue<300){
digitalWrite(DRY_PIN,HIGH);
delay(2000);
digitalWrite(DRY_PIN,LOW);
currentState = idle;
return currentState;
break;
}
//if voltage is not in economy mode, we will dry 7 seconds
digitalWrite(DRY_PIN,HIGH);
delay(7000);
digitalWrite(DRY_PIN,LOW);
currentState = idle;
return currentState;
break;
}
case superDeluxeWash:
{
Serial.println("super deluxe wash");
//Washes dishes in hot water for 7 minutes, then in medium water (both hot and cold) for 7 minutes, then finally runs the dryer for 7 minutes.
//hot wash for 7 minutes
digitalWrite(LOCK_PIN,HIGH);
digitalWrite(HOT_PIN,HIGH);
delay(7000);
//medium wash for 7 minutes
digitalWrite(HOT_PIN,HIGH);
digitalWrite(COLD_PIN,HIGH);
delay(7000);
digitalWrite(HOT_PIN,LOW);
digitalWrite(COLD_PIN,LOW);
double sensorValue = analogRead(POT_PIN);
//if voltage is in economy mode, we will dry for 2 seconds and break
if(sensorValue<300){
digitalWrite(DRY_PIN,HIGH);
delay(2000);
digitalWrite(DRY_PIN,LOW);
currentState = idle;
return currentState;
break;
}
//dry for 7 minutes otherwise
digitalWrite(DRY_PIN,HIGH);
delay(7000);
currentState = idle;
return currentState;
break;
}
}
}