import time
from machine import Pin
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
# Define the GPIO pins
pin1 = Pin(14, Pin.IN, Pin.PULL_DOWN)
pin2 = Pin(15, Pin.IN, Pin.PULL_DOWN)
pin3 = Pin(16, Pin.IN, Pin.PULL_DOWN)
pin4 = Pin(17, Pin.IN, Pin.PULL_DOWN)
# Define the state combinations and corresponding letters
states = {
(0, 0, 0, 0): 1,
(0, 0, 0, 1): 2,
(0, 0, 1, 0): 3,
(0, 0, 1, 1): 4,
(0, 1, 0, 0): 5,
(0, 1, 0, 1): 6,
(0, 1, 1, 0): 7,
(0, 1, 1, 1): 8,
(1, 0, 0, 0): 9,
(1, 0, 0, 1): 10,
(1, 0, 1, 0): 11,
(1, 0, 1, 1): 12,
(1, 1, 0, 0): 13,
(1, 1, 0, 1): 14,
(1, 1, 1, 0): 15,
(1, 1, 1, 1): 0
}
while True:
# Read the pin values
pin1_state = pin1.value()
pin2_state = pin2.value()
pin3_state = pin3.value()
pin4_state = pin4.value()
# Create a tuple of the pin states
current_state = (pin1_state, pin2_state, pin3_state, pin4_state)
# Get the corresponding letter
value = states.get(current_state, 'Combination not defined')
print(f"Current State: {current_state}, Number: {value}")
time.sleep(2)