# Basic_DIP.py
# The value being set by dip switches
#
# Joshua Mo-Yung, March 22,2024
# SN: 100830422
from machine import Pin
import time
# GP's to be used as In (0=lsb)pins = [machine.Pin(i, machine.Pin.IN for i in (0, 1, 2, 3)]
pins = [machine.Pin(i, machine.Pin.IN) for i in (0, 1, 2, 3)]
# GP's to be used, with Pull_down
pins = [machine.Pin(i, machine.Pin.IN, machine.Pin.PULL_DOWN) for i in (0, 1, 2, 3)]
binV = 0 # calculate and updates the weight of the binary input value
back = 0 # Temporary holder for binary input value
def update(binV):
'''get the Sp offset value (binary weights [0..15]) - passed 0, at every call,
in case of a change'''
if pins[0].value() == 1:
binV = binV + 1
if pins[1].value() == 1:
binV = binV + 2
if pins[2].value() == 1:
binV = binV + 4
if pins[3].value() == 1:
binV = binV + 8
return binV
while True:
back = 0
back = update(back)
print("Binary weight value = " + str(back))
time.sleep_ms(1000) # cause the TC to update at 1 second intervals