from machine import Pin
from utime import sleep
# 7-segment display layout
# A
# ---
# F | G | B
# ---
# E | | C
# ---
# D
pins1 = [
Pin(2, Pin.OUT), # A
Pin(3, Pin.OUT), # B
Pin(4, Pin.OUT), # C
Pin(5, Pin.OUT), # D
Pin(6, Pin.OUT), # E
Pin(8, Pin.OUT), # F
Pin(7, Pin.OUT), # G
Pin(0, Pin.OUT),
]
pins2 = [
Pin(21, Pin.OUT),
Pin(22, Pin.OUT),
Pin(1, Pin.OUT),
Pin(20, Pin.OUT),
Pin(19, Pin.OUT),
Pin(16, Pin.OUT),
Pin(17, Pin.OUT),
Pin(0, Pin.OUT),
]
# Common anode 7-segment display digit patterns
digits10 = [
[0, 0, 0, 0, 0, 0, 1, 1], # 0
]
digits11 = [
[1, 0, 0, 1, 1, 1, 1, 1],
]
digits12 = [
[0, 0, 1, 0, 0, 1, 0, 1],
]
digits13 = [
[0, 0, 0, 0, 1, 1, 0, 1],
]
digits14 = [
[1, 0, 0, 1, 1, 0, 0, 1],
]
digits15 = [
[0, 1, 0, 0, 1, 0, 0, 1],
]
digits16 = [
[0, 1, 0, 0, 0, 0, 0, 1],
]
digits17 = [
[0, 0, 0, 1, 1, 1, 1, 1],
]
digits18 = [
[0, 0, 0, 0, 0, 0, 0, 1],
]
digits19 = [
[0, 0, 0, 0, 1, 0, 0, 1],
]
digits101 = [
[0, 0, 0, 0, 0, 0, 1, 1], # 0
]
digits21 = [
[1, 0, 0, 1, 1, 1, 1, 1],
]
digits22 = [
[0, 0, 1, 0, 0, 1, 0, 1],
]
digits20 = [
[0, 0, 0, 0, 0, 0, 1, 1],
]
def reset1():
for pin in pins1:
pin.value(1)
def reset2():
for pin in pins2:
pin.value(1)
reset1()
reset2()
switch = Pin(13, Pin.IN)
switch2 = Pin(18, Pin.IN)
while True:
sleep(1.5)
for i in range(len(digits10)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits10[i][j])
sleep(0.5)
for i in range(len(digits20)):
if switch.value() == 0:
break
for j in range(len(pins2) - 1):
pins2[j].value(digits20[i][j])
sleep(0.5)
if switch.value() == 1:
# Ascending counter
for i in range(len(digits11)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits11[i][j])
sleep(0.5)
# Ascending counter
for i in range(len(digits12)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits12[i][j])
sleep(0.5)
# Ascending counter
for i in range(len(digits13)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits13[i][j])
sleep(0.5)
# Ascending counter
for i in range(len(digits14)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits14[i][j])
sleep(0.5)
for i in range(len(digits15)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits15[i][j])
sleep(0.5)
for i in range(len(digits16)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits16[i][j])
sleep(0.5)
for i in range(len(digits17)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits17[i][j])
sleep(0.5)
for i in range(len(digits18)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits18[i][j])
sleep(0.5)
for i in range(len(digits19)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits19[i][j])
sleep(0.5)
for i in range(len(digits101)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits101[i][j])
sleep(0.5)
for i in range(len(digits21)):
if switch.value() == 0:
break
for j in range(len(pins2) - 1):
pins2[j].value(digits21[i][j])
sleep(0.5)
for i in range(len(digits11)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits11[i][j])
sleep(0.5)
# Ascending counter
for i in range(len(digits12)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits12[i][j])
sleep(0.5)
# Ascending counter
for i in range(len(digits13)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits13[i][j])
sleep(0.5)
# Ascending counter
for i in range(len(digits14)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits14[i][j])
sleep(0.5)
for i in range(len(digits15)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits15[i][j])
sleep(0.5)
for i in range(len(digits16)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits16[i][j])
sleep(0.5)
for i in range(len(digits17)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits17[i][j])
sleep(0.5)
for i in range(len(digits18)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits18[i][j])
sleep(0.5)
for i in range(len(digits19)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits19[i][j])
sleep(0.5)
for i in range(len(digits101)):
if switch.value() == 0:
break
for j in range(len(pins1) - 1):
pins1[j].value(digits101[i][j])
sleep(0.5)
for i in range(len(digits22)):
if switch.value() == 0:
break
for j in range(len(pins2) - 1):
pins2[j].value(digits22[i][j])
sleep(0.5)
for i in range(len(digits20)):
if switch.value() == 0:
break
for j in range(len(pins2) - 1):
pins2[j].value(digits20[i][j])
sleep(0.5)