Skip to content

Commit c46b57c

Browse files
author
Mikey Sklar
committed
added seven segment clock with zero padding
1 parent 35f7b2f commit c46b57c

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import time
2+
import datetime
3+
from adafruit_ht16k33 import segments
4+
import board
5+
import busio
6+
7+
# Create the I2C interface.
8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
10+
# Create the LED segment class.
11+
# This creates a 7 segment 4 character display:
12+
display = segments.Seg7x4(i2c)
13+
14+
# clear display
15+
display.fill(0)
16+
17+
while True:
18+
# get system time
19+
now = datetime.datetime.now()
20+
hour = now.hour
21+
minute = now.minute
22+
second = now.second
23+
24+
# setup HH:MM for display and print it
25+
clock = '%02d%02d' % (hour,minute) # concat hour + minute, add leading zeros
26+
display.print(clock)
27+
28+
# Toggle colon when displaying time
29+
if second % 2:
30+
display.print(':') # Enable colon every other second
31+
else:
32+
display.print(';') # Turn off colon
33+
34+
time.sleep(0.5)
35+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_ht16k33 import segments
5+
6+
# Create the I2C interface.
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
9+
# Create the LED segment class.
10+
# This creates a 7 segment 4 character display:
11+
display = segments.Seg7x4(i2c)
12+
13+
# Clear the display.
14+
display.fill(0)
15+
16+
# Can just print a number
17+
display.print(42)
18+
time.sleep(1)
19+
20+
# Set the first character to '1':
21+
display[0] = '1'
22+
# Set the second character to '2':
23+
display[1] = '2'
24+
# Set the third character to 'A':
25+
display[2] = 'A'
26+
# Set the forth character to 'B':
27+
display[3] = 'B'
28+
time.sleep(1)
29+
30+
numbers = [0.0, 1.0, -1.0, 0.55, -0.55, 10.23, -10.2, 100.5, -100.5]
31+
32+
# print negative and positive floating point numbers
33+
for i in numbers:
34+
display.print(i)
35+
time.sleep(0.5)
36+
37+
# print hex values, enable colon
38+
for i in range(0xFF):
39+
display.fill(0)
40+
display.print(':')
41+
display.print(hex(i))
42+
time.sleep(0.25)

0 commit comments

Comments
 (0)