Exemplo n.º 1
0
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
Exemplo n.º 2
0
def relay1Change(): #Callback function for Relay 1
    if(rly1Cntl.value=='CLOSE'):
        TINK.relayOFF(0,1)
    else:
        TINK.relayON(0,1)
Exemplo n.º 3
0
def relay2Change(): #Callback function for Relay 2
    if(rly1Cnt2.value=='CLOSE'):
        TINK.relayOFF(0,2)
    else:
        TINK.relayON(0,2)
Exemplo n.º 4
0
import piplates.TINKERplate as TINK
import time

TINK.setDEFAULTS(0)  #initialize Digital I/O ports
TINK.setMODE(0, 2, 'din')  #set port 2 as an input for the motion sensor
TINK.setMODE(0, 3, 'dout')  #set port 3 as an output for the siren

while (True):
    motion = TINK.getDIN(0, 2)  #read motion sensor status
    if (motion == 1):  #if motion detected
        TINK.relayON(0, 1)  #turn on lamp
        TINK.setDOUT(0, 3)  #turn on siren
    else:  #if no motion
        TINK.relayOFF(0, 1)  #turn off lamp
        TINK.clrDOUT(0, 3)  #turn off siren
    time.sleep(0.1)  #wait 100msec and repeat