-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWashingMachine_MIcro.ino
More file actions
218 lines (158 loc) · 4.83 KB
/
WashingMachine_MIcro.ino
File metadata and controls
218 lines (158 loc) · 4.83 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
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
#include <MsTimer2.h>
// constants won't change. They're used here to
// set pin numbers:
const int DrainButton = 4; // the number of the pushbutton pin
const int WashButton = 3;
const int OffButton = 2; // the number of the pushbutton pin
const int SpinButton = 5; // the number of the pushbutton pin
const int LidButton = 6;
const int RotationRelay = 9;
const int WashMotor = 8; // the number of the LED pin
const int SpinMotor = 7; // the number of the LED pin
// Variables will change:
int ledState = LOW; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
int SpinState = LOW; // the current state of the output pin
int SpinButtonState; // the current reading from the input pin
int lastSpinState = LOW; // the previous reading from the input pin
int OffState = LOW; // the current state of the output pin
int OffButtonState; // the current reading from the input pin
int lastOffButtonState = LOW; // the previous reading from the input pin
int DrainState = LOW; // the current state of the output pin
int DrainButtonState; // the current reading from the input pin
int lastDrainButtonState = LOW; // the previous reading from the input pin
int A = 0 ;
int var = 0;
int RelayState = LOW;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000;
void setup() {
pinMode(OffButton, INPUT_PULLUP);
pinMode(DrainButton, INPUT_PULLUP);
pinMode(SpinButton, INPUT_PULLUP);
pinMode(WashButton, INPUT_PULLUP);
pinMode(LidButton, INPUT_PULLUP);
pinMode(WashMotor, OUTPUT);
pinMode(SpinMotor, OUTPUT);
pinMode(RotationRelay, OUTPUT);
// set initial LED state
digitalWrite(SpinMotor, LOW);
digitalWrite(WashMotor, LOW);
digitalWrite(RotationRelay, LOW);
MsTimer2::set(1000, TimerEvent); // 5 minutes period
}
void loop() {
Wash();
Spin();
Drain();
Off();
}
void Spin()
{
int reading = digitalRead(SpinButton);
if (reading != lastSpinState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != SpinButtonState) {
SpinButtonState = reading;
if ((SpinButtonState == LOW) && (LidButton == LOW)) {
var = 0;
MsTimer2::start();
digitalWrite(WashMotor, LOW);
digitalWrite(SpinMotor, HIGH);
delay(10000);
digitalWrite(WashMotor, HIGH);
}
}
}
lastSpinState = reading;
}
void Wash()
{
int reading = digitalRead(WashButton);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
digitalWrite(SpinMotor, LOW);
digitalWrite(WashMotor, HIGH);
var = 1;
MsTimer2::start();
}
}
}
if (var == 1){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (RelayState == LOW){
RelayState = HIGH;
//delay(1000);
digitalWrite(RotationRelay, LOW);
digitalWrite(WashMotor, HIGH);
} else {
//delay(1000);
digitalWrite(WashMotor, LOW);
digitalWrite(RotationRelay, HIGH);
RelayState = LOW;
}
//digitalWrite(WashMotor, HIGH);
}
}
// set the LED:
lastButtonState = reading;
}
void Off()
{
int reading = digitalRead(OffButton);
if (reading != lastOffButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != OffButtonState) {
OffButtonState = reading;
if (OffButtonState == LOW) {
digitalWrite(WashMotor, LOW);
digitalWrite(SpinMotor, LOW);
digitalWrite(RotationRelay, LOW);
var = 0 ;
}
}
}
lastOffButtonState = reading;
}
void Drain()
{
int reading = digitalRead(DrainButton);
if (reading != lastDrainButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != DrainButtonState) {
DrainButtonState = reading;
if (DrainButtonState == LOW) {
digitalWrite(WashMotor, LOW);
digitalWrite(SpinMotor, HIGH);
var = 0;
}
}
}
lastDrainButtonState = reading;
}
void TimerEvent()
{
A++;
if (A == 60*30 )
{
Off();
MsTimer2::stop();
A= 1;
}
}