@@ -7,15 +7,15 @@ LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
7
7
8
8
// initialize a few values
9
9
int last_panel = 0 ;
10
- int press_count = 0 ;
11
10
int timer = 0 ;
12
11
int rtemp = 0 ;
13
12
int system_mode = 0 ;
14
13
int fan_mode = 0 ;
14
+ int ctemp = 0 ;
15
+ int humidity_lvl = 0 ;
15
16
16
17
int max_panels = 4 ;
17
18
int panel_num = 1 ;
18
- int ctemp = 77 ;
19
19
20
20
// address of where were going to store the value in eeprom
21
21
int rtemp_address = 0 ;
@@ -85,7 +85,7 @@ void loop() {
85
85
lcd_key = read_LCD_buttons (); // read the buttons
86
86
87
87
// check for button activity, if not, turn off backlight
88
- if (lcd_key < 5 ) {
88
+ if (lcd_key < btnNONE ) {
89
89
digitalWrite (BACKLIGHT, HIGH);
90
90
timer = 0 ;
91
91
// if its been awhile since anyone touched a button, lets turn off the backlight
@@ -96,16 +96,16 @@ void loop() {
96
96
lcd.setCursor (0 ,0 );
97
97
98
98
// Check values from LCD Keypad
99
- if (lcd_key == 3 ) {
99
+ if (lcd_key == btnLEFT ) {
100
100
// Left
101
101
state = 1 ;
102
- } else if (lcd_key == 0 ){
102
+ } else if (lcd_key == btnRIGHT ){
103
103
// Right
104
104
state = 2 ;
105
- } else if (lcd_key == 1 ){
105
+ } else if (lcd_key == btnUP ){
106
106
// Up
107
107
state = 3 ;
108
- } else if (lcd_key == 2 ){
108
+ } else if (lcd_key == btnDOWN ){
109
109
// Down
110
110
state = 4 ;
111
111
}
@@ -141,7 +141,7 @@ void loop() {
141
141
}
142
142
143
143
// display panel, but dont keep recreating it if no button is pressed
144
- if (panel_num == 1 || lcd_key != 5 ) {
144
+ if (panel_num == 1 || lcd_key != btnNONE ) {
145
145
displayPanel (panel_num,lcd_key);
146
146
}
147
147
@@ -155,13 +155,14 @@ void loop() {
155
155
156
156
void humidity () {
157
157
// code to get DHT reading coming soon
158
- int humidity_lvl = 44 ;
158
+ humidity_lvl = 44 ;
159
159
lcd.print (" Humidity: " );
160
160
lcd.print (humidity_lvl);
161
161
lcd.print (" %" );
162
162
}
163
163
164
164
void dht_temperature () {
165
+ ctemp = 77 ;
165
166
lcd.setCursor (0 ,0 );
166
167
lcd.print (" Cur Temp: " );
167
168
lcd.print (ctemp);
@@ -174,9 +175,9 @@ void requested_temperature(int lcd_key) {
174
175
// rtemp
175
176
176
177
// add or increase temp based on up/down arrow
177
- if (lcd_key == 1 ) {
178
+ if (lcd_key == btnUP ) {
178
179
rtemp = rtemp + 1 ;
179
- }else if (lcd_key == 2 ) {
180
+ }else if (lcd_key == btnDOWN ) {
180
181
rtemp = rtemp - 1 ;
181
182
}
182
183
@@ -186,42 +187,45 @@ void requested_temperature(int lcd_key) {
186
187
lcd.print ((char )223 );
187
188
188
189
// whene select button pressed, we save the data to eeprom and print SAVED to lcd
189
- if (lcd_key == 4 ) {
190
+ if (lcd_key == btnSELECT ) {
190
191
lcd.clear ();
191
192
eeprom_write (rtemp_address, rtemp);
192
193
}
193
194
}
194
195
195
196
void mode (int lcd_key) {
196
197
197
- // example system_mode value from eeprom
198
- // system_mode = 2;
199
-
200
198
lcd.print (" Mode: " );
201
-
202
- // press_count used for cycling through values below
203
- press_count++;
204
199
lcd.setCursor (6 ,0 );
205
- switch (press_count % 3 ) {
200
+
201
+ // Now change the unsaved mode
202
+ if (lcd_key == btnUP) {
203
+ if (system_mode < 2 ) system_mode++;
204
+ }
205
+ else if (lcd_key == btnDOWN) {
206
+ if (system_mode > 0 ) system_mode--;
207
+ }
208
+ switch (system_mode) {
206
209
case 0 :
207
210
lcd.print (" Off " );
208
- system_mode = 0 ;
209
211
break ;
210
212
case 1 :
211
213
lcd.print (" Cool" );
212
- system_mode = 1 ;
213
214
break ;
214
215
case 2 :
215
216
lcd.print (" Heat" );
216
- system_mode = 2 ;
217
+ break ;
218
+ default :
219
+ // if somehow, mode gets out of range, do something
220
+ // about it here. Sensible fail-safe default may be OFF?
221
+ system_mode = 0 ;
217
222
break ;
218
223
}
219
-
220
224
// whene select button pressed, we save the data to eeprom and print SAVED to lcd
221
- if (lcd_key == 4 ) {
225
+ if (lcd_key == btnSELECT ) {
222
226
lcd.clear ();
223
227
eeprom_write (mode_address, system_mode);
224
- }
228
+ }
225
229
}
226
230
227
231
void fan (int lcd_key) {
@@ -230,11 +234,16 @@ void fan(int lcd_key) {
230
234
// fan_mode = 1;
231
235
232
236
lcd.print (" Fan: " );
233
-
234
- // press_count used for cycling through values below
235
- press_count++;
236
237
lcd.setCursor (5 ,0 );
237
- switch (press_count % 2 ) {
238
+
239
+ // Now change the unsaved mode
240
+ if (lcd_key == btnUP) {
241
+ if (fan_mode < 1 ) fan_mode++;
242
+ }
243
+ else if (lcd_key == btnDOWN) {
244
+ if (fan_mode > 0 ) fan_mode--;
245
+ }
246
+ switch (fan_mode) {
238
247
case 0 :
239
248
lcd.print (" Auto" );
240
249
fan_mode = 0 ;
@@ -245,10 +254,8 @@ void fan(int lcd_key) {
245
254
break ;
246
255
}
247
256
248
- Serial.println (press_count);
249
-
250
257
// whene select button pressed, we save the data to eeprom and print SAVED to lcd
251
- if (lcd_key == 4 ) {
258
+ if (lcd_key == btnSELECT ) {
252
259
lcd.clear ();
253
260
eeprom_write (fan_address, fan_mode);
254
261
}
0 commit comments