# imports
from machine import Pin, ADC, Timer
import time

DIG_1 = 7
DOT_PIN = 11
# BUTTON_PIN = 22
ANALOG_PIN = 28

displayCodes = [
    0xC0,
    0xF9,
    0xA4,
    0xB0,
    0x99,
    0x92,
    0x82,
    0xF8,
    0x80,
    0x90
]

display_value = 0000


def read_analogue_voltage(pin):
    global display_value
    analog_value = ADC(pin).read_u16()
    display_value = round(3.3 * analog_value / 65535 * 1000)
    print(f"Voltage: {display_value} mV")

def scan_display():
        temp_display_value = display_value
        for i in range(3, -1, -1):
            display_digit(int(temp_display_value%10), i, i==0)
            time.sleep(1 / 60)
            Pin(DIG_1 + i, Pin.OUT).off()
            Pin(DOT_PIN, Pin.OUT).value(1)
            temp_display_value /= 10

def display_digit(digit_value, digit_index, dp_enable=False):
    for i in range(7):
        Pin(i, Pin.OUT).value((1<<i) & displayCodes[digit_value])
    Pin(DIG_1 + digit_index, Pin.OUT).on()
    if dp_enable:
        Pin(DOT_PIN, Pin.OUT).value(0)

last_time = time.ticks_add(time.ticks_ms(), -300)
update_voltage = False

def interrupt_callback(pin):
    global last_time, update_voltage
    if time.ticks_diff(time.ticks_ms(), last_time) > 200:
        last_time = time.ticks_ms()
        update_voltage = True

def main():
    global update_voltage
    Timer().init(period=1000, mode=Timer.PERIODIC, callback=interrupt_callback)
    for i in range(4):
        Pin(DIG_1 + i, Pin.OUT).value(0)
    Pin(DOT_PIN, Pin.OUT).value(0)

    while True:
        if update_voltage:
            read_analogue_voltage(28)
            update_voltage = False
        scan_display()

if __name__ == '__main__':
    main()
$abcdeabcde151015202530fghijfghij
$abcdeabcde151015202530fghijfghij
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT