-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLOCK.ino
More file actions
69 lines (68 loc) · 1.08 KB
/
Copy pathCLOCK.ino
File metadata and controls
69 lines (68 loc) · 1.08 KB
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
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int hrs = 12;
int mins = 0;
int sec = 0;
int TIME = 0;
const int bhrs = A4;
const int bmins = A5;
int state1 = 0;
int state2 = 0;
void setup()
{
lcd.begin(16, 2);
pinMode(bhrs, INPUT_PULLUP);
pinMode(bmins, INPUT_PULLUP);
}
void loop()
{
lcd.setCursor(0, 0);
sec = sec + 1;
lcd.print("TIME:" );
lcd.print(hrs);
lcd.print(":");
lcd.print(mins);
lcd.print(":");
lcd.print(sec);
if (TIME ==12) {
lcd.print(" PM");
}
if (TIME == 24) TIME = 0;
delay(800);
lcd.clear();
if (sec == 60)
{
sec = 0;
mins = mins + 1;
}
if (mins == 60)
{
mins = 0;
hrs = hrs + 1;
TIME = TIME + 1;
}
if (hrs == 13)
{
hrs = 1;
}
lcd.setCursor(0, 1);
lcd.print("Simple Clock ");
state1 = digitalRead(bhrs);
if (state1 == 0)
{
hrs = hrs + 1;
TIME = TIME + 1;
if (TIME==12){
lcd.print(" PM");
}
if (TIME == 24) TIME = 0;
if (hrs == 13)
hrs = 1;
}
state2 = digitalRead(bmins);
if (state2 == 0)
{
sec = 0;
mins = mins + 1;
}
}