-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDryer.ino
246 lines (224 loc) · 5.86 KB
/
Dryer.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include "SevSeg.h"
#include <OneWire.h>
#include <DS18B20.h>
#include <ButtonDebounce.h>
#include <EEPROM.h>
#define ONE_WIRE_BUS 14
#define GET_PERIOD 3000
#define INC_PERIOD 500
#define BLNK_PERIOD 1000
#define TEMP_MIDDLE 215
#define TEMP_MODE 0
#define TEMP_ALARM_MODE 1
#define TOP_LEVEL_MODE 2
#define BOT_LEVEL_MODE 3
#define RELAY_PIN 13
OneWire oneWire(ONE_WIRE_BUS);
DS18B20 sensor(&oneWire);
int temp=0;
byte topTempTreshhold=5;
byte botTempTreshhold=5;
unsigned int menuMode=0;
unsigned long incTimer;
bool alarmFlag=false;
SevSeg sevseg; //Instantiate a seven segment controller object
ButtonDebounce buttonL(2, 250);
ButtonDebounce buttonC(3, 250);
ButtonDebounce buttonR(4, 250);
ButtonDebounce buttonA(17, 250);
bool checkIncPromt(void)
{
if (millis() - incTimer >= INC_PERIOD)
{
//Serial.println(millis() - incTimer);
incTimer = millis();
/*
Serial.print("topTempTreshhold ");
Serial.print(topTempTreshhold+TEMP_MIDDLE);
Serial.print(" botTempTreshhold ");
Serial.println(TEMP_MIDDLE-botTempTreshhold);*/
return 1;
}
return 0;
}
void buttonLChanged(int state)
{
//Serial.println("L Changed: " + String(state));
if (((menuMode==TEMP_MODE)||(menuMode==TEMP_ALARM_MODE))&&(state==0))
{
menuMode=BOT_LEVEL_MODE;
}
if ((menuMode==BOT_LEVEL_MODE)&&(state==0))
{
if ((botTempTreshhold<255)&&(checkIncPromt()==1))
{
botTempTreshhold++;
}
}
if ((menuMode==TOP_LEVEL_MODE)&&(state==0))
{
if ((topTempTreshhold>10)&&(checkIncPromt()==1))
{
topTempTreshhold--;
}
}
}
void buttonCChanged(int state)
{
//Serial.println("C Changed: " + String(state));
if (menuMode!=TEMP_MODE)
{
EEPROM.write(0, botTempTreshhold);
EEPROM.write(1, topTempTreshhold);
}
menuMode=TEMP_MODE;
}
void buttonRChanged(int state)
{
//Serial.println("R Changed: " + String(state));
if (((menuMode==TEMP_MODE)||(menuMode==TEMP_ALARM_MODE))&&(state==0))
{
menuMode=TOP_LEVEL_MODE;
}
if ((menuMode==BOT_LEVEL_MODE)&&(state==0))
{
if ((botTempTreshhold>10)&&(checkIncPromt()==1))
{
botTempTreshhold--;
}
}
if ((menuMode==TOP_LEVEL_MODE)&&(state==0))
{
if ((topTempTreshhold<255)&&(checkIncPromt()==1))
{
topTempTreshhold++;
}
}
}
void setup()
{
byte numDigits = 3;
byte digitPins[] = {12, 11, 10};
byte segmentPins[] = {A2, A5, 8, 6, 5, A1, 9, 7};
bool resistorsOnSegments = true; // 'false' means resistors are on digit pins
byte hardwareConfig = NP_COMMON_CATHODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(100);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH);
Serial.begin(115200);
Serial.println(__FILE__);
sensor.begin();
sensor.requestTemperatures();
incTimer = millis();
botTempTreshhold = EEPROM.read(0);
topTempTreshhold = EEPROM.read(1);
Serial.print("topTempTreshhold ");
Serial.print(topTempTreshhold+TEMP_MIDDLE);
Serial.print(" botTempTreshhold ");
Serial.println(TEMP_MIDDLE-botTempTreshhold);
/*
buttonL.setCallback(buttonLChanged);
buttonC.setCallback(buttonCChanged);
buttonR.setCallback(buttonRChanged);
*/
}
void loop()
{
static unsigned long getTimer = millis();
static unsigned long blinkTimer = millis();
buttonL.update();
buttonC.update();
buttonR.update();
buttonA.update();
if(buttonL.state() == LOW)
{
buttonLChanged(0);
}
if(buttonC.state() == LOW)
{
buttonCChanged(0);
}
if(buttonR.state() == LOW)
{
buttonRChanged(0);
}
if(buttonA.state() == LOW)
{
digitalWrite(RELAY_PIN, HIGH);
Serial.println("Alarm OFF Button");
}
switch(menuMode)
{
case TEMP_MODE:
sevseg.setNumber(temp, 1);
if(alarmFlag==true)
{
alarmFlag=false;
digitalWrite(RELAY_PIN, HIGH);
Serial.println("Alarm OFF return in range");
}
break;
case TEMP_ALARM_MODE:
if((digitalRead(RELAY_PIN)==HIGH)&&(alarmFlag==false))
{
alarmFlag=true;
digitalWrite(RELAY_PIN, LOW);
Serial.println("Alarm ON");
}
if (millis() - blinkTimer >= BLNK_PERIOD)
{
sevseg.setNumber(temp, 1);
}
else
{
sevseg.blank();
}
if (millis() - blinkTimer >= BLNK_PERIOD*2)
{
blinkTimer += BLNK_PERIOD*2;
}
if (sensor.isConversionComplete());
{
/*Serial.print("temp: ");
Serial.println(sensor.gettempC());*/
temp=(int)sensor.getTempC()*10;
//sevseg.setNumber(temp, 1);
sensor.requestTemperatures();
}
break;
case TOP_LEVEL_MODE:
sevseg.setNumber(TEMP_MIDDLE+topTempTreshhold, 1);
break;
case BOT_LEVEL_MODE:
sevseg.setNumber(TEMP_MIDDLE-botTempTreshhold, 1);
break;
default :
break;
}
if (millis() - getTimer >= GET_PERIOD)
{
getTimer += GET_PERIOD;
if (sensor.isConversionComplete());
{
/*Serial.print("temp: ");
Serial.println(sensor.gettempC());*/
temp=(int)sensor.getTempC()*10;
if ((menuMode==TEMP_MODE)&&((temp>topTempTreshhold+TEMP_MIDDLE)||(temp<TEMP_MIDDLE-botTempTreshhold)))
{
menuMode=TEMP_ALARM_MODE;
}
else if ((menuMode==TEMP_ALARM_MODE)&&((temp<topTempTreshhold+TEMP_MIDDLE)&&(temp>TEMP_MIDDLE-botTempTreshhold)))
{
menuMode=TEMP_MODE;
}
//sevseg.setNumber(temp, 1);
sensor.requestTemperatures();
}
}
sevseg.refreshDisplay();
}