-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino_simple_clock_ht16k33.ino
138 lines (115 loc) · 3.24 KB
/
arduino_simple_clock_ht16k33.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
/*
* This example displays simple arduino clock displayed in 7 segment using Ht16k33
*
* pin config:
scl - On Arduino UNO thats Analog #5, on the Leonardo its Digital #3, on the Mega its digital #21
sda - On Arduino UNO thats Analog #4, on the Leonardo its Digital #2, on the Mega its digital #20
vcc - +5 V
Gnd - 0 V
A0 - A segment
A1 - B
A2 - C
A3 - D
.
.
.
.
A7 - Decimal point
c0 - cathode 1
c1 - cathode 2
c2 - colon cathode
c3 - cathode 3
c4 - cathode 4
arduino
pin 10 = push button for minute
pin 11 = push button for hour (To increase hour & min you need to pull down the push button to ground )
created 12 Dec. 2017
by Deepan
*
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment(); // creating function for first Ht16k33 (0x70)
int h=12,m,s,bl=0;
int flag,TIME;
String clc;
const int hs=11;
const int ms=10;
int state1;
int state2;
void setup()
{
Serial.begin(9600);
pinMode(hs, INPUT_PULLUP);
pinMode(ms, INPUT_PULLUP);
Serial.println(" Seven Segment Display Test");
matrix.begin(0x70); // creating first matrix
matrix.setBrightness(15); // setting brightness for display (0 - 15)
//matrix.blinkRate(1) ; // You can blink the entire display. 0 is no blinking. 1, 2 or 3 is for display blinking.
}
void loop()
{
s=s+1; // second increment
clc="Time = "; // storing time in string
clc=clc+h;
clc=clc+":"+m;
clc=clc+":"+s;
if(flag<12)
clc=clc+"AM";
if(flag==12)
clc=clc+"PM";
if(flag>12)
clc=clc+"PM";
Serial.println(clc); // printing time in serial
matrix.clear(); // clearing chip memory
matrix.writeDigitNum(0,(h/10)) ; // writing first digit of hour
matrix.writeDigitNum(1,(h%10)) ; // writing second digit of hour
matrix.writeDigitNum(3,(m/10)) ; // writing first digit of min
matrix.writeDigitNum(4,(m%10)) ; // writing second digit of min
matrix.writeDigitNum(2,bl) ; // blinking dot
matrix.writeDisplay(); // displaying
bl++; //dot increament
if(bl==9)
bl=0;
if(flag==24)
flag=0;
delay(1000);
if(s==60) // second
{
s=0;
m=m+1;
}
if(m==60) // minute
{
m=0;
h=h+1;
flag=flag+1;
}
if(h==13) // hour
{
h=1;
}
//-------Time // setting-------//
state1=digitalRead(hs);
if(state1==0)
{
h=h+1;
flag=flag+1;
if(flag<12)
Serial.print("AM");
if(flag==12)
Serial.print("PM");
if(flag>12)
Serial.print("PM");
if(flag==24)
flag=0;
if(h==13)h=1;
}
state2=digitalRead(ms);
if(state2==0)
{
s=0;
m=m+1;
}
}