I2c-7-segment-led

From aldeid
Jump to navigation Jump to search

Diagram

Code

#!/usr/bin/env python3

from datetime import datetime
import time
import board
import busio
from adafruit_ht16k33 import segments
i2c = busio.I2C(board.SCL, board.SDA)
display = segments.Seg7x4(i2c)
display.fill(0)
display.print(':')

try:
    while True:
        now = datetime.now()
        now_str = now.strftime("%H%M")
                
        #display.fill(0) # reset display
        display[0] = now_str[0]
        display[1] = now_str[1]
        display[2] = now_str[2]
        display[3] = now_str[3]
            
        # debug
        print(now.strftime("%H:%M:%S"))
        
        time.sleep(1)

except KeyboardInterrupt:
    display.fill(0)