-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCD_DISPLAY.ino
137 lines (110 loc) · 2.51 KB
/
LCD_DISPLAY.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
#define LED_Line 13
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
class MyClock
{
private:
unsigned int seconds, minutes, hours, days, years;
public:
MyClock(unsigned int s, unsigned int m, unsigned int h, unsigned int d, unsigned int y)
{
seconds = s;
minutes = m;
hours = h;
days = d;
years = y;
}
void increment_seconds(void)
{
//increment seconds
seconds++;
//if seconds is greater than a minute
if(seconds >= 60)
{
//make seconds = 0
seconds = 0;
minutes++;
if(minutes >= 60)
{
minutes = 0;
hours++;
if(hours >= 24)
{
hours = 0;
days++;
if(days >= 365)
{
days = 0;
years++;
}
}
}
}
}
unsigned long getTime(void)
{
unsigned long temp = 0;
temp = days;
temp = temp << 8;
temp |= hours;
temp = temp << 8;
temp |= minutes;
temp = temp << 8;
temp |= seconds;
return temp;
}
};//End of clock class
unsigned long time1 = 0;
unsigned long time2 = 0;
MyClock myClock(0, 0, 0, 0, 0);
void setup() {
// put your setup code here, to run once:++
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("HI");
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop()
{
String message = " ";
unsigned long currentTime = 0;
//Get current timestamp
time2 = micros();
// if time difference is greater than 1s( 1s = 1000000 * 1 ms)
if((time2 - time1) >= 1000000)
{
//save timestamp
time1 = time2;
//increment seconds
myClock.increment_seconds();
//get current time
currentTime = myClock.getTime();
//compose a time message
message = "TIME: ";
message += currentTime >> 24;
message += ":";
message += ((currentTime >> 16) & 0xFF);
message += ":";
message += ((currentTime >> 8) & 0xFF);
message += ":";
message += ((currentTime >> 0) & 0xFF);
//Display on serial port
Serial.print(01);
if(currentTime%2 == 0)
{
//lcd.print("First line");
lcd.setCursor(0,1);
lcd.print("1");
digitalWrite(13, HIGH);
}
else
{
//lcd.print("Second line");
lcd.setCursor(0,1);
lcd.print("2");
digitalWrite(13, LOW);
}
}
}