from machine import *
from time import *
# GPIO Pins for the 7-segment display
segments = [machine.Pin(i, machine.Pin.OUT) for i in range(1, 8)]
# Number to 7-segment mapping
num_map = {
'0': (1, 1, 1, 1, 1, 1, 0),
'1': (0, 1, 1, 0, 0, 0, 0),
'2': (1, 1, 0, 1, 1, 0, 1),
'3': (1, 1, 1, 1, 0, 0, 1),
'4': (0, 1, 1, 0, 0, 1, 1),
'5': (1, 0, 1, 1, 0, 1, 1),
'6': (1, 0, 1, 1, 1, 1, 1),
'7': (1, 1, 1, 0, 0, 0, 0),
'8': (1, 1, 1, 1, 1, 1, 1),
'9': (1, 1, 1, 1, 0, 1, 1),
}
def display_digit(digit):
""" Display a single digit on the 7-segment display """
for seg, state in zip(segments, num_map[digit]):
seg.value(state) # Ensure seg is a GPIO object
while True:
current_time = time.localtime()
# Display hours
display_digit(str(current_time.tm_hour // 10))
time.sleep(1)
display_digit(str(current_time.tm_hour % 10))
time.sleep(1)
# Display minutes
display_digit(str(current_time.tm_min // 10))
time.sleep(1)
display_digit(str(current_time.tm_min % 10))
time.sleep(1)