import piplates.TINKERplate as TINK
import time

tripTEMP = 78  #this is the temperature we will operate around
hysteresis = 1  #we will add a small amount of hysteresis to avoid chatter

threshold = tripTEMP - hysteresis  #the on/off threshold is the tripTEMP +/- the hysteresis
fanON = True  #initialize flag and..
TINK.relayON(0, 1)  #turn on fan

TINK.setDEFAULTS(0)  #set all Digital I/O ports to their default states
TINK.setMODE(0, 1, 'temp')  #set the mode of Digital I/O port 1 to temperature

while (True):  #start loop
    temp = TINK.getTEMP(0, 1)  #collect temperature data
    if (fanON):
        if (temp < threshold):  #if on and temp is below threshold:
            fanON = False  #clear state
            TINK.relayOFF(0, 1)  #turn off fan
            threshold = tripTEMP + hysteresis  #set high threshold
    else:
        if (temp > threshold):  #if off and temp is above threshold:
            fanON = True  #set state true
            TINK.relayON(0, 1)  #turn on fan
            threshold = tripTEMP - hysteresis  #set low threshold
    print("Temperature:", temp, ", Fan State:", fanON)
    time.sleep(1)  #sleep 1 sec then
import piplates.TINKERplate as TINK  #load TINKERplate module
import time                          #load time functions
d = '\u00b0'
TINK.setDEFAULTS(0)         #set all digital channel to defaults.
TINK.setMODE(0,1,'temp')    #Set channel 1 to read a temperature sensor
time.sleep(1)               #wait 1 second for stabilization
TINK.openMETER()            #Create a display meter on the screen
TINK.setTITLE('My Thermometer')
while(True):
    temp=TINK.getTEMP(0,1)
    TINK.setMETER(temp,d+'F','Channel 1:')
    time.sleep(1)
import piplates.TINKERplate as TINK  #load TINKERplate module
import time  #load time functions
d = '\u00b0'  #create the degree symbol
TINK.setMODE(0, 1, 'temp')  #setmode
while (True):  #loop forever
    t = TINK.getTEMP(0, 1)  #fetch temperature
    #print to the console
    print('Time:', time.ctime(), ' - Temperature is:', t,
          d + 'F')  #print to the console
    time.sleep(1)  #delay 1 second