from machine import Pin
import time
import oled
import sensor
heat = Pin(26, Pin.OUT, Pin.PULL_DOWN)
temp_set = 66
temp_buf = 1
def heat_check(temp_cur):
global heat, temp_set, temp_buf
lower_bound = temp_set - temp_buf
upper_bound = temp_set + temp_buf
# Check if we need to turn off the heat
if temp_cur > upper_bound and heat.value() == 1: # Heat is on
heat.value(0)
print("Turning off heat...")
elif temp_cur < lower_bound and heat.value() == 0: # Heat is off
heat.value(1)
print("Turning on heat...")
while True:
sensor.get_readings()
current_temp_f = sensor.get_tempf()
current_rh = sensor.get_rh()
heat_check(current_temp_f['num'])
oled.show_stats(current_temp_f['str'], str(temp_set), current_rh)
time.sleep(5)
Call-for-Heat Circuit (Furnace)