Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views9 pages

Arduino Mega Si Modem590

This document describes an Arduino project that displays time, date and sensor data on an LCD screen. It initializes the LCD and sets pin assignments for buttons and LEDs. It defines functions for the main page, settings page and button presses. The main page shows time, date, day of week and sensor readings. The settings page allows navigating and selecting options to set time, date, alarms and settings using buttons.

Uploaded by

Digital Xlescu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Arduino Mega Si Modem590

This document describes an Arduino project that displays time, date and sensor data on an LCD screen. It initializes the LCD and sets pin assignments for buttons and LEDs. It defines functions for the main page, settings page and button presses. The main page shows time, date, day of week and sensor readings. The settings page allows navigating and selecting options to set time, date, alarms and settings using buttons.

Uploaded by

Digital Xlescu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1 #include <LiquidCrystal.

h>
2 const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
3 LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
4 //------------------------------------------------------------------------------
5 int ledState = HIGH;
6 int buttonState; // the current reading from the input pin
7 int lastButtonState = LOW; // the previous reading from the input pin
8 // the following variables are unsigned longs because the time, measured in
9 // milliseconds, will quickly become a bigger number than can be stored in an int.
10 unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
11 unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
12
13
14
15 //-----------------------------------------------------------------------------
16 int btp[5]={6,7,8,9,10}; //Input Pins
17 /*
18 btp[0]=Buton Left =Pin 6
19 btp[1]=Buton Right =Pin 7
20 btp[2]=Buton Down =Pin 8
21 btp[3]=Buton Up =Pin 9
22 btp[4]=Buton Select =Pin 10
23 */
24 int oPin[5]={30,31,32,33,34}; //Output pins - Leduri
25 int cursorPosition = 0;
26 //======================================================
27 String MLuna[12]={"Ianuarie","Februarie","Martie","Aptilie","Mai","Iunie","Iulie","August",
"Septembrie","Octombrie","Noiembrie","Decembrie"};
28 String MZiua[7]={"Luni","Marti","Miercuri","Joi","Vineri","Sambata","Duminica"};
29 const char *const MyMenu[][5] PROGMEM = {
30 {"Timp" , "Ora" , "Minut" , "Secunda", "ok1"},
31 {"Data" , "Anul" , "Luna" , "Ziua", "ok2"},
32 {"Alarma1" , "Data" , "Ora" , "Motiv", "ok3"},
33 {"Setari" , "Pornit" , "Oprit" , "Anulat", "ok4"}
34 };
35 boolean Page_to_LCD=LOW;
36 /*
37 ---------------------------------------------------------------------------------------
38 Main page
39 ================
40 ================
41 ================
42 ================
43 00:00:00 -time
44 00-00-000 -data
45 -00.00.%
46 -00.00 C
47
48 Show time and date-Main Pages
49 Settings-Time
50 -Ora
51 -Minute
52 -Secunde
53 -Clear
54 -Enter
55 -Back
56 -Date
57 -Ziua
58 -Luna
59 -An
60 -Prima zi a saptamani(Luni sau duminica)
61 -Ziua din saptamana
62 -Clear
63 -Enter
64 -Back
65 -Alarma
66 -Alarma 1
67 -Alarma 2
68 -Alarma 3
69
70
71 */
72 //==================================================*/
73 //==========================================
74
75 //===========================================
76 void setup() {
77 lcd.begin(20,4);
78 lcd.clear();
79 sett_P();
80 lcd.setCursor(0, 0);
81 lcd.print("Set Pins OK");
82 delay(1500);
83 lcd.clear();
84 }
85
86 //==================================================
87 void loop() {
88 if (Page_to_LCD==LOW){
89 MPage();
90 }
91 else {
92 SPage();
93 }
94
95 FButon();
96 //MPage();
97 }
98 //=====================Setare pinout====================
99 void sett_P(){
100 lcd.setCursor(5, 3);
101 lcd.print("Set Pins ....");
102 delay(100);
103 for (int thisPin=0; thisPin<=4; thisPin++){
104 pinMode(btp[thisPin],INPUT_PULLUP);
105 pinMode(oPin[thisPin],OUTPUT);
106 digitalWrite(oPin[thisPin],LOW);
107 delay(100);
108 }
109
110 lcd.clear();
111 }
112 //================Functii butoane=============================
113 void FButon(){
114
115 int reading = digitalRead(6); // se citeste Left pentru a se vedea starea LOW sau HIGH
116 if (reading != lastButtonState) { //daca citirea este diferita fata de valoaea initiala
117 lastDebounceTime = millis();
118 }
119 if ((millis() - lastDebounceTime) > debounceDelay) {
120 if (reading != buttonState) {
121 buttonState = reading;
122 if (buttonState == HIGH) {
123 Page_to_LCD=LOW;
124 //ledState =! ledState;
125 }
126 else {
127 Page_to_LCD=HIGH;
128 }
129 }
130 }
131
132 lastButtonState = reading;
133
134
135
136
137 /*
138
139 if (digitalRead(6) == LOW)
140 {
141 Page_to_LCD==0;
142
143 lcd.setCursor(8, 0);
144 lcd.print("Left");
145 //digitalWrite(oPin[0],HIGH);
146 }
147 else
148 {
149 Page_to_LCD==1;
150 //lcd.clear();
151 // digitalWrite(oPin[0], LOW);
152 }
153
154 if (digitalRead(7) == LOW)
155 {
156 lcd.setCursor(8, 0);
157 lcd.print("Right");
158 digitalWrite(oPin[1],HIGH);
159 }
160 else
161 {
162 lcd.clear();
163 digitalWrite(oPin[1], LOW);
164 }
165 */
166
167 }
168
169
170 //main Page
171 void MPage(){
172 lcd.setCursor(0, 0);
173 lcd.print(" Ora Data");
174 lcd.setCursor(0, 1);
175 //lcd.print(DateTime(__DATE__, __TIME__));
176 lcd.print("24:00:00 * 31/12/'19");
177 lcd.setCursor(0, 1);
178 //lcd.print("00:00:00 * 00/00/0000");
179 lcd.setCursor(0,2 );
180 lcd.print(MZiua[3]);
181 lcd.setCursor(0,3 );
182 lcd.print("T:+20.00C U:60.00 %");
183 }
184 //==================================================
185 void SPage(){
186 lcd.setCursor(0, 0);
187 lcd.print(" Ora Data");
188 lcd.setCursor(0, 1);
189
190 //lcd.print(DateTime(__DATE__, __TIME__));
191 lcd.print("Coman * Danut");
192 lcd.setCursor(0, 1);
193 //lcd.print("00:00:00 * 00/00/0000");
194 lcd.setCursor(0,2 );
195 lcd.print(MZiua[3]);
196 lcd.setCursor(0,3 );
197
198 lcd.print("T:+20.00C U:60.00 %");
199 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216 //=======================================================
217 void cdan(){
218 lcd.clear();
219 lcd.setCursor(3,1 );
220 lcd.print(MyMenu[0][5] );
221 //bCursor();
222 delay(1000);
223 lcd.clear();
224 }
225
226 void bCursor(){
227 lcd.setCursor(10,1 );
228 lcd.cursor();
229 delay(300);
230 lcd.noCursor();
231 delay(300);
232 lcd.clear();
233 }
234
235
236 /*
237
238 ================================resturi cod==================
239 //const int bLeft = 6; btp[] // the number of the pushbutton pin
240 const int bRight = 7;
241 const int bUp= 8;
242 const int bDown= 9;
243 const int bSelect=10;
244 int buttonState = 0;
245 =============================================================
246 ////buttonState = 0;
247
248 //////buttonState = digitalRead(bSelect);
249
250 // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
251 ///// if (buttonState == HIGH) {
252 // turn LED on:
253 ////digitalWrite(ledPin, LOW);
254 //// } else {
255 // turn LED off:
256 ///digitalWrite(ledPin, HIGH);
257 /// }
258 //lcd.setCursor(0, 1);
259 //lcd.print(millis() / 1000);
260 //bCursor();
261
262 =======================================================
263 // Creates 3 custom characters for the menu display
264 byte downArrow[8] = {0b00100,0b00100,0b00100,0b00100, 0b00100, 0b10101, 0b01110,0b00100};
265 byte upArrow[8] = {0b00100, 0b01110,0b10101, 0b00100, 0b00100, 0b00100, 0b00100};
266 byte menuCursor[8] = {B01000, B00100, B00010,B00001,B00010, B00100, B01000, B00000 };
267
268
269
270 */
271
272
273
274
275
276
277
278
279
280
281
282
283 //#include <LiquidCrystal.h>
284 //const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
285 //LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
286 ////-----------------------------------------------------------------------------
287 //int btp[6]={6,7,8,9,10,13};
288 //int cursorPosition = 0;
289 ////======================================================
290 //const char *const MyMenu[][5] PROGMEM = {
291 // {"Timp" , "Ora" , "Minut" , "Secunda", "ok1"},
292 // {"Data" , "Anul" , "Luna" , "Ziua", "ok2"},
293 // {"Alarma1" , "Data" , "Ora" , "Motiv", "ok3"},
294 // {"Setari" , "Pornit" , "Oprit" , "Anulat", "ok4"}
295 //};
296 ////---------------------------------------------------------------------------------------
297 ////Show time and date-Main Page
298 ////Settings-Time
299 //// -Ora
300 //// -Minute
301 //// -Secunde
302 //// -Clear
303 //// -Enter
304 //// -Back
305 //// -Date
306 //// -Ziua
307 //// -Luna
308 //// -An
309 //// -Prima zi a saptamani(Luni sau duminica)
310 //// -Ziua din saptamana
311 //// -Clear
312 //// -Enter
313 //// -Back
314 //// -Alarma
315 //// -Alarma 1
316 //// -Alarma 2
317 //// -Alarma 3
318 ////==================================================
319 //const int bLeft = 6; // the number of the pushbutton pin
320 //const int bRight = 8;
321 //const int bUp= 7;
322 //const int bDown= 9;
323 //const int bSelect=10;
324 //const int ledPin = 13;
325 //int buttonState = 0;
326 ////==========================================
327 //// Creates 3 custom characters for the menu display
328 //byte downArrow[8] = {0b00100,0b00100,0b00100,0b00100, 0b00100, 0b10101, 0b01110,0b00100};
329 //byte upArrow[8] = {0b00100, 0b01110,0b10101, 0b00100, 0b00100, 0b00100, 0b00100};
330 //byte menuCursor[8] = {B01000, B00100, B00010,B00001,B00010, B00100, B01000, B00000
};
331 //
332 ////===========================================
333 //void setup() {
334 // lcd.begin(20,4);
335 // lcd.clear();
336 // sett_P();
337 // lcd.setCursor(0, 0);
338 //lcd.clear();
339 //}
340 //
341 ////==================================================
342 //void loop() {
343 //
344 //buttonState = 0;
345 //
346 // buttonState = digitalRead(bSelect);
347 //
348 // // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
349 // if (buttonState == HIGH) {
350 // // turn LED on:
351 // digitalWrite(ledPin, HIGH);
352 // } else {
353 // // turn LED off:
354 // digitalWrite(ledPin, LOW);
355 // }
356 // //lcd.setCursor(0, 1);
357 // //lcd.print(millis() / 1000);
358 ////bCursor();
359 //}
360 ////=====================Setare pinout====================
361 //void sett_P(){
362 // for (int thisPin=0; thisPin<=5; thisPin++){
363 // pinMode(btp[thisPin],INPUT);
364 // delay(500);
365 // lcd.setCursor(0, 3);
366 // lcd.print(btp[thisPin]);
367 // }
368 //}
369 ////================Functii butoane=============================
370 //void FButon(){
371 //
372 //}
373 ////=======================================================
374 //void cdan(){
375 //lcd.clear();
376 //lcd.setCursor(3,1 );
377 // lcd.print(MyMenu[0][5] );
378 ////bCursor();
379 //delay(1000);
380 //lcd.clear();
381 //}
382 //
383 //void bCursor(){
384 //lcd.setCursor(10,1 );
385 //lcd.cursor();
386 //delay(300);
387 // lcd.noCursor();
388 //delay(300);
389 //lcd.clear();
390 //}
391
392
393 //// NJarpa
394 //// LCD 16x2 Multiple screens example
395 //
396 //#include <LiquidCrystal.h>
397 //
398 //LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //To lcd (RS,E,D4,D5,D6,D7)
399 //
400 ////Counter to change positions of pages
401 //
402 //int page_counter=1 ; //To move beetwen pages
403 //
404 //
405 ////-------Pins-----//
406 //int up = 8; //Up button
407 //int down = 10; //Down button
408 ////---------Storage debounce function-----//
409 //boolean current_up = LOW;
410 //boolean last_up=LOW;
411 //boolean last_down = LOW;
412 //boolean current_down = LOW;
413 //
414 //
415 //void setup() {
416 // lcd.begin(16,2);
417 //
418 //}
419 //
420 //
421 // //---- De-bouncing function for all buttons----//
422 //boolean debounce(boolean last, int pin)
423 //{
424 //boolean current = digitalRead(pin);
425 //if (last != current)
426 //{
427 //delay(5);
428 //current = digitalRead(pin);
429 //}
430 //return current;
431 //}
432 //
433 //
434 //void loop() {
435 //
436 //current_up = debounce(last_up, up); //Debounce for Up button
437 //current_down = debounce(last_down, down); //Debounce for Down button
438 //
439 ////----Page counter function to move pages----//
440 //
441 ////Page Up
442 // if (last_up== LOW && current_up == HIGH){ //When up button is pressed
443 // lcd.clear(); //When page is changed, lcd clear to print new
page
444 // if(page_counter <3){ //Page counter never higher than 3(total of pages)
445 // page_counter= page_counter +1; //Page up
446 //
447 // }
448 // else{
449 // page_counter= 3;
450 // }
451 // }
452 //
453 // last_up = current_up;
454 //
455 ////Page Down
456 // if (last_down== LOW && current_down == HIGH){ //When down button is pressed
457 // lcd.clear(); //When page is changed, lcd clear to print new
page
458 // if(page_counter >1){ //Page counter never lower than 1 (total of pages)
459 // page_counter= page_counter -1; //Page down
460 //
461 // }
462 // else{
463 // page_counter= 1;
464 // }
465 // }
466 //
467 // last_down = current_down;
468 //
469 ////------- Switch function to write and show what you want---//
470 // switch (page_counter) {
471 //
472 // case 1:{ //Design of home page 1
473 // lcd.setCursor(5,0);
474 // lcd.print("This is");
475 // lcd.setCursor(3,1);
476 // lcd.print(" Home Page");
477 // }
478 // break;
479 //
480 // case 2: { //Design of page 2
481 // lcd.setCursor(5,0);
482 // lcd.print("This is");
483 // lcd.setCursor(5,1);
484 // lcd.print("Page 2");
485 // }
486 // break;
487 //
488 // case 3: { //Design of page 3
489 // lcd.setCursor(1,0);
490 // lcd.print("You are now on");
491 // lcd.setCursor(4,1);
492 // lcd.print("Page 3");
493 // }
494 // break;
495 //
496 // }//switch end
497 //
498 //}//loop end
499 //
500 //
501 ////

You might also like