code.py
 1  # SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  import datetime
 7  from adafruit_ht16k33 import segments
 8  import board
 9  import busio
10  
11  # Create the I2C interface.
12  i2c = busio.I2C(board.SCL, board.SDA)
13  
14  # Create the LED segment class.
15  # This creates a 7 segment 4 character display:
16  display = segments.Seg7x4(i2c)
17  
18  # clear display
19  display.fill(0)
20  
21  while True:
22      # get system time
23      now = datetime.datetime.now()
24      hour = now.hour
25      minute = now.minute
26      second = now.second
27  
28      # setup HH:MM for display and print it
29      clock = '%02d%02d' % (hour,minute)          # concat hour + minute, add leading zeros
30      display.print(clock)
31  
32      # Toggle colon when displaying time
33      if second % 2:
34          display.print(':')                      # Enable colon every other second
35      else:
36          display.print(';')                      # Turn off colon
37  
38      time.sleep(0.5)