# Basic_TC.py - A Basic On/Off temperature controller
# The base setpoint (Sp) = 20℃, but with the added value being set on 4 dip switches
# (connected to 4 input pins)
# and offset can applied, lifting the setpoint to between 20 & 35℃
# The temperature sensor is the, PicoW onboard sensor.
# If the sampled temperature(Pv) is < the setpoint, an output is set.
# When the sampled temperature(Pv) is >= the setpoint(Sp), the output is cleared.
# The output will stay off until the sensor value has dropped by Setpoint(Sp) - 2℃
# (the differential).
#
# Phil J, Mar 24
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)]
# GP's to be used as In (0=lsb)
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 # Calculates and updates the weight of the binry 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