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
def dout8Change(): #Callback function for digital output 8 if(doutCnt8.value=='SET'): TINK.setDOUT(0,8) else: TINK.clrDOUT(0,8)
stringP=stringO #set LEDs to OFF zone=0 elif(dist>dClose): stringP=stringG #set LEDs to green zone=1 elif(dist>dGood): stringP=stringY #set LEDs to yellow zone=2 elif(dist>dDanger): stringP=stringR #set LEDs to red zone=3 else: stringP=stringR #inside danger zone - set LEDs to red blink=True #enable blinking alarm=True #enable alarm zone=4 if((blink and bToggle) or (blink==False)): TINK.setRGBSTRING(0,1,stringP) #send eight LED values to port 1 else: TINK.setRGBSTRING(0,1,stringO) #send right off LEDs to port 1 if(alarm): TINK.setDOUT(0,5) #turn on alarm if enabled else: TINK.clrDOUT(0,5) #turn off alarm otherwise if (bToggle): #toggle bToggle bToggle=False else: bToggle=True except: print("Stabilizing") time.sleep(0.2) #sleep 100msec before repeating