from machine import Pin
import time
# Define pins for each segment in the 7-segment display
a = Pin(23, Pin.OUT)
b = Pin(22, Pin.OUT)
c = Pin(21, Pin.OUT)
d = Pin(19, Pin.OUT)
e = Pin(18, Pin.OUT)
f = Pin(5, Pin.OUT)
g = Pin(17, Pin.OUT)
db = Pin(16, Pin.OUT)
# Define pins for controlling the four displays
first_seven = Pin(4, Pin.OUT)
second_seven = Pin(2, Pin.OUT)
third_seven = Pin(0, Pin.OUT)
fourth_seven = Pin(15, Pin.OUT)
# Function to clear all segments
def clear_display():
a.value(1)
b.value(1)
c.value(1)
d.value(1)
e.value(1)
f.value(1)
g.value(1)
# Functions to display numbers from 0 to 9
def display_digit(digit):
clear_display()
if digit == 0:
a.value(0)
b.value(0)
c.value(0)
d.value(0)
e.value(0)
f.value(0)
elif digit == 1:
b.value(0)
c.value(0)
elif digit == 2:
a.value(0)
b.value(0)
d.value(0)
e.value(0)
g.value(0)
elif digit == 3:
a.value(0)
b.value(0)
c.value(0)
d.value(0)
g.value(0)
elif digit == 4:
b.value(0)
c.value(0)
f.value(0)
g.value(0)
elif digit == 5:
a.value(0)
c.value(0)
d.value(0)
f.value(0)
g.value(0)
elif digit == 6:
a.value(0)
c.value(0)
d.value(0)
e.value(0)
f.value(0)
g.value(0)
elif digit == 7:
a.value(0)
b.value(0)
c.value(0)
elif digit == 8:
a.value(0)
b.value(0)
c.value(0)
d.value(0)
e.value(0)
f.value(0)
g.value(0)
elif digit == 9:
a.value(0)
b.value(0)
c.value(0)
d.value(0)
f.value(0)
g.value(0)
# Function to display time in HH:MM format
def display_time(hours, minutes):
clear_display()
# Display hours
first_seven.value(1)
display_digit(hours // 10) # Tens place of hours
first_seven.value(0)
time.sleep(0.002) # Short delay
second_seven.value(1)
display_digit(hours % 10) # Units place of hours
second_seven.value(0)
time.sleep(0.002) # Short delay
# Display minutes
third_seven.value(1)
display_digit(minutes // 10) # Tens place of minutes
third_seven.value(0)
time.sleep(0.002) # Short delay
fourth_seven.value(1)
display_digit(minutes % 10) # Units place of minutes
fourth_seven.value(0)
time.sleep(0.002) # Short delay
# Main loop to start from 13:30 and increment time
hours = 13 # Starting hour
minutes = 30 # Starting minute
while True:
display_time(hours, minutes)
time.sleep(1) # Update every second
minutes += 1 # Increment minutes
if minutes >= 60: # If minutes reach 60, reset to 0 and increment hours
minutes = 0
hours += 1
if hours >= 24: # Reset hours after 23
hours = 0