from machine import Pin, ADC
import time
# ===== Display subsystem: seven segments, driven directly =================
SEG_PINS = [26, 27, 14, 12, 13, 27, 33] # a, b, c, d, e, f, g
segs = [Pin(n, Pin.OUT) for n in SEG_PINS]
# Bit i of each pattern drives segment i (a=bit0 ... g=bit6).
DIGITS = [
0b0111111, # 0: a b c d e f
0b0000110, # 1: b c
0b1011011, # 2: a b d e g
0b1001111, # 3: a b c d g
0b1100110, # 4: b c f g
0b1101101, # 5: a c d f g
0b1111101, # 6: a c d e f g
0b0000111, # 7: a b c
0b1111111, # 8: all seven
0b1101111, # 9: a b c d f g
]
def show(digit):
pattern = DIGITS[digit]
for i in range(7):
seg[i].value((pattern >> i) & 1)
# ===== Sensing subsystem: one analog input ================================
pot = ADC(Pin(34))
pot.atten(ADC.ATTN_11DB) # full 0 - 3.3 V range, readings 0 - 4095
# ===== Main program =======================================================
print("Dial Display running. Turn the potentiometer...")
last_digit = -1
while True:
raw = pot.read() # 0 .. 4095
digit = raw * 10 // 4096
if digit != last_digit:
last_digit = digit
print("raw =", raw, "-> digit =", digit)
show(digit)
time.sleep(0.2)