from machine import Pin
from time import sleep as delay
# Definition of Pins connected to Seven Segments Display
A = Pin(2,Pin.OUT)
B = Pin(0,Pin.OUT)
C = Pin(4,Pin.OUT)
D = Pin(16,Pin.OUT)
E = Pin(17,Pin.OUT)
F = Pin(18,Pin.OUT)
G = Pin(5,Pin.OUT)
seg_lst = [A,B,C,D,E,F,G] # group the pins to list
# list of lists of pins to be turned on to display decimal digit
dig_seg_lst=[[A,B,C,D,E,F],
[B,C],
[A,B,G,D,E],
[A,B,C,D,G],
[F,G,C,B],
[A,F,G,C,D],
[A,C,D,E,F,G],
[A,B,C],
[A,B,C,D,E,F,G],
[A,B,C,D,F,G]]
while True:
for i in range(len(dig_seg_lst)): #for each decimal digit
#check all the connected pins
for segment in seg_lst:
if segment in dig_seg_lst[i]:
#if it's in the digit list turn it on. else off
segment.on()
else:
segment.off()
#display the digit for 1 second
delay(1)