-
Notifications
You must be signed in to change notification settings - Fork 6
/
Calentador.ino
263 lines (222 loc) · 5.38 KB
/
Calentador.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* Nokia 3310/5110, 84x48 pixel monochrome LCD display.
*/
#include <MenuPCD8544.h>
#include <AnalogKeyPad.h>
#include <PID_v1.h>
#include <oven.h>
#include <thermo.h>
#include "menu.h"
#include "parameters.h"
extern const menu_t menuRoot;
extern Adafruit_PCD8544 lcd;
extern AnalogKeyPad keypad;
extern MenuPCD8544 menuMain;
double temp= 5, tempAnt;
extern uint16_t tempLimit1;
extern bool showMenuFlag;
extern uint8_t backLightMode;
extern uint32_t autoOffValue;
extern bool alarmEnabled;
extern unsigned long counter;
extern bool isBacklightOn;
extern OvenControl calentador;
extern double setPoint;
extern bool itsRun;
extern bool itsStop;
extern bool waitAHitToUpdate;
void printPrincipal();
unsigned long nextCheck=millis();
void setup()
{
lcd.begin();
lcd.setRotation(2);
lcd.cp437(true);
pinMode(BACKLIGHTPIN, OUTPUT);
pinMode(ALARMINDICATORPIN, OUTPUT);
analogReference(DEFAULT);
backLightMode = 0;
digitalWrite(BACKLIGHTPIN, LOW);
//PID
setPoint=100;
calentador.setAccuracy(2);
calentador.setPWMSkip(0);
calentador.myPID->SetTunings(KP, KI, KD);
calentador.moveTo(setPoint);
//FIN PID
printPrincipal();
tone(ALARMSOUNDPIN, 820, 300);
delay(100);
tone(ALARMSOUNDPIN, 260, 200);
delay(100);
tone(ALARMSOUNDPIN, 440, 300);
delay(100);
noTone(ALARMSOUNDPIN);
}
void loop()
{
menuFunc_t selection;
int8_t keyCode;
tempAnt = temp;
temp = calentador.getActualTemperature();
//PID
if (millis() > nextCheck && itsRun && !itsStop)
{
nextCheck += 50;
//Serial.println(temp);
calentador.run();
if(!calentador.finished())
{
//Serial.println("Controlando temp");
calentador.moveTo(setPoint);
}
else
{
//Serial.println("Dentrol del rango");
calentador.stop();
}
}//FIN PID
if( alarmEnabled )
{
if( (tempLimit1-5)<=temp )
{
digitalWrite(ALARMINDICATORPIN, HIGH);
tone(ALARMSOUNDPIN, 2000, 50);
delay(150);
tone(ALARMSOUNDPIN, 2000, 100);
}
else
{
digitalWrite(ALARMINDICATORPIN, LOW);
noTone(ALARMSOUNDPIN);
}
}
if( (temp != tempAnt) && (!showMenuFlag) && (!waitAHitToUpdate))
{
printTemp(temp);
lcd.display();
}
if( (!isBacklightOn) && (backLightMode==2) ) // Si esta apagado, modo auto y mostrando temps
{
if( keypad.keyUpEvent() != AnalogKeyPad::NO_KEY )
{
counter = millis();
digitalWrite(BACKLIGHTPIN, HIGH);
isBacklightOn = true;
}
}
else
{
if( !waitAHitToUpdate )
{
if( !showMenuFlag )
{
if( keypad.keyUpEvent() != AnalogKeyPad::NO_KEY )
{
if(backLightMode==2)
counter = millis();
if( (keypad.getCurrentKey() == AnalogKeyPad::UP ) && !itsStop )
{
runPauseProcess();
printPrincipal();
}
if( keypad.getCurrentKey() == AnalogKeyPad::SELECT )
{
tone(ALARMSOUNDPIN, 200, 200);
delay(100);
tone(ALARMSOUNDPIN, 440, 300);
delay(100);
noTone(ALARMSOUNDPIN);
lcd.clearDisplay();
showMenuFlag = true;
menuMain.begin(&lcd);
}
}
}
else
{
selection = taskMenu(); // run the menu task
if ( selection != NULL ) // menu item selected?
{
showMenuFlag = false;
(*selection)(); // then execute it
if( !waitAHitToUpdate )
{
printPrincipal();
}
tone(ALARMSOUNDPIN, 480, 300);
delay(100);
tone(ALARMSOUNDPIN, 200, 200);
delay(100);
noTone(ALARMSOUNDPIN);
}
}
}
else
if( keypad.keyUpEvent() != AnalogKeyPad::NO_KEY )
{
waitAHitToUpdate = false;
printPrincipal();
}
}
if( (backLightMode==2) && ((millis()-counter) > autoOffValue) )
{
digitalWrite(BACKLIGHTPIN, LOW);
isBacklightOn = false;
}
}
// handle the menu
menuFunc_t taskMenu()
{
menuFunc_t doit = NULL;
int8_t keyCode;
if ( (keyCode = keypad.keyUpEvent()) != AnalogKeyPad::NO_KEY ) // was key pressed?
{
if( (!isBacklightOn) && (backLightMode==2) )
{
digitalWrite(BACKLIGHTPIN, HIGH);
isBacklightOn = true;
}
counter = millis();
tone(ALARMSOUNDPIN, 440, 50);
delay(50);
noTone(ALARMSOUNDPIN);
// valid input keycodes: U,D,L,R,S - Up, Down, Left, Right, Select
// returns true if menu item was selected and *doit holds the associated function pointer
int8_t selected = menuMain.navigate(keyCode, &doit);
if (selected) // user selected the menu item
{
if (doit == MenuPCD8544::canceled) // check that the menu was not canceled
{ doit = NULL;
printPrincipal();
showMenuFlag = false;
}
}
} // end process keycode
return doit;
}
void printPrincipal()
{
lcd.clearDisplay();
lcd.setTextSize(1);
lcd.setTextColor(BLACK, WHITE);
if( !itsStop )
{
lcd.print("Setpoint= ");
lcd.print((uint16_t)setPoint);
if( !itsRun )
setStatus(" Paused");
else
setStatus(" Running...");
}
else
{
lcd.print("Temperatura");
setStatus(" OK -> Menu");
}
lcd.setTextSize(2);
lcd.setCursor(53, 14);
lcd.print((char)248);
lcd.print("C");
temp --;
}