from machine import Pin
import time
SEG_A_PIN = 2
SEG_B_PIN = 3
SEG_C_PIN = 4
SEG_D_PIN = 5
SEG_E_PIN = 6
SEG_F_PIN = 7
SEG_G_PIN = 8
POSITION_1 = 10
POSITION_2 = 11
POSITION_3 = 12
POSITION_4 = 13
DIVIDER_COLON = 22
DIGITS :[Pin] = []
POSITIONS : [Pin] = []
def setup():
# Define each segment
SEG_A = Pin(SEG_A_PIN, Pin.OUT)
SEG_B = Pin(SEG_B_PIN, Pin.OUT)
SEG_C = Pin(SEG_C_PIN, Pin.OUT)
SEG_D = Pin(SEG_D_PIN, Pin.OUT)
SEG_E = Pin(SEG_E_PIN, Pin.OUT)
SEG_F = Pin(SEG_F_PIN, Pin.OUT)
SEG_G = Pin(SEG_G_PIN, Pin.OUT)
# Define which segments make up each digit
DIGIT_0 = [SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F ]
DIGIT_1 = [ SEG_B, SEG_C ]
DIGIT_2 = [SEG_A, SEG_B, SEG_D, SEG_E, SEG_G]
DIGIT_3 = [SEG_A, SEG_B, SEG_C, SEG_D, SEG_G]
DIGIT_4 = [ SEG_B, SEG_C, SEG_F, SEG_G]
DIGIT_5 = [SEG_A, SEG_C, SEG_D, SEG_F, SEG_G]
DIGIT_6 = [SEG_A, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G]
DIGIT_7 = [SEG_A, SEG_B, SEG_C ]
DIGIT_8 = [SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G]
DIGIT_9 = [SEG_A, SEG_B, SEG_C, SEG_D, SEG_F, SEG_G]
POS_1 = Pin(POSITION_1, Pin.OUT)
POS_2 = Pin(POSITION_2, Pin.OUT)
POS_3 = Pin(POSITION_3, Pin.OUT)
POS_4 = Pin(POSITION_4, Pin.OUT)
global divider_colon
divider_colon = Pin(DIVIDER_COLON, Pin.OUT)
global DIGITS
DIGITS = [DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9]
global POSITIONS
POSITIONS = [POS_1, POS_2, POS_3, POS_4]
displayOff()
def showPosition(position):
positionsOff()
position.on()
def displayDigit(digit):
segmentsOff()
for segment in digit:
segment.off()
def positionsOff():
for pos in POSITIONS:
pos.off()
def segmentsOff():
for segment in DIGITS[8]:
segment.on()
def displayOff():
positionsOff()
segmentsOff()
setup()
while True:
for position in POSITIONS:
showPosition(position)
for digit in DIGITS:
displayDigit(digit)
time.sleep(0.2)
divider_colon.toggle()