from machine import Pin
import time
# GP's to be used as inputs for switches
switch_pins = [Pin(i, Pin.IN, Pin.PULL_DOWN) for i in (0, 1, 2, 3)]
def read_switches():
'''Reads the state of the four switches and returns a binary value'''
binary_value = 0
for i, pin in enumerate(switch_pins):
if pin.value() == 1:
binary_value |= (1 << i) # Set the corresponding bit in binary_value
return binary_value
while True:
binary_value = read_switches()
print("Binary value from switches:", binary_value)
time.sleep_ms(1000) # Update every 1 second