import machine
import utime

# Define the segment pins (A-G)
segments = [
    machine.Pin(0, machine.Pin.OUT),  # A
    machine.Pin(1, machine.Pin.OUT),  # B
    machine.Pin(2, machine.Pin.OUT),  # C
    machine.Pin(3, machine.Pin.OUT),  # D
    machine.Pin(4, machine.Pin.OUT),  # E
    machine.Pin(5, machine.Pin.OUT),  # F
    machine.Pin(6, machine.Pin.OUT),  # G
]

# Define the digit pins (D1-D4)
digit_pins = [
    machine.Pin(7, machine.Pin.OUT),  # Digit 1
    machine.Pin(8, machine.Pin.OUT),  # Digit 2
    machine.Pin(9, machine.Pin.OUT),  # Digit 3
    machine.Pin(10, machine.Pin.OUT), # Digit 4
]

# Define the number mapping for the 7-segment display
number_map = [
    [1, 1, 1, 1, 1, 1, 0],  # 0
    [0, 1, 1, 0, 0, 0, 0],  # 1
    [1, 1, 0, 1, 1, 0, 1],  # 2
    [1, 1, 1, 1, 0, 0, 1],  # 3
    [0, 1, 1, 0, 0, 1, 1],  # 4
    [1, 0, 1, 1, 0, 1, 1],  # 5
    [1, 0, 1, 1, 1, 1, 1],  # 6
    [1, 1, 1, 0, 0, 0, 0],  # 7
    [1, 1, 1, 1, 1, 1, 1],  # 8
    [1, 1, 1, 1, 0, 1, 1]   # 9
]

def display_number(digit, number):
    for pin in digit_pins:
        pin.value(1)
    
    for i in range(7):
        segments[i].value(number_map[number][i])
    
    # Turn on the specific digit pin
    digit_pins[digit].value(0)

# Function to update the display with all digits
def update_display():
    for digit in range(4):
        display_number(digit, digit_values[digit])
        utime.sleep_ms(1)  


digit_values = [0, 0, 0, 0]

while True:
    for digit in range(4):
        user_input = int(input(f'Enter digit {digit + 1} (0-9): '))
        digit_values[digit] = user_input
        
        
        update_display()
    
    # After all digits are entered, keep displaying the numbers for 10 seconds
    start_time = utime.ticks_ms()
    while utime.ticks_diff(utime.ticks_ms(), start_time) < 10000:  # 10 seconds
        update_display()
    
    # After 10 seconds, restart the loop to get new input
    print("10 seconds have passed. Restarting...")

        
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT