def int_apionics(): """ Initialize the servos and define channels. """ # Bank (roll_deg), channel 8, servo control, settle time TINK.setMODE(0,8,'servo') time.sleep(0.5) # Variometer, channel 1, servo control, settle time TINK.setMODE(0,1,'servo') time.sleep(0.5) # Fuel gauge, channel 2, servo control, settle time TINK.setMODE(0,2,'servo') time.sleep(0.5)
import piplates.TINKERplate as TINK import time TINK.setDEFAULTS(0) #return all ports to their default states TINK.setMODE(0,8,'servo') #set Digital I/O port 1 to drive a servo lLimit=12.0 #The lower limit = 0 volts hLimit=166.0 #The upper limit = 12 volts while(True): analogIn=TINK.getADC(0,1) #read analog channel 1 #scale the data to an angle in the range of lLimit to hLimit angle=analogIn*(hLimit-lLimit)/12.0 TINK.setSERVO(0,8,lLimit+angle) #set servo angle time.sleep(.1) #delay and repeat
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 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 import time #create battery state thresholds VL = 1.2 VH = 1.4 TINK.setDEFAULTS(0) TINK.setMODE(0, 1, 'rgbled') #set Digital I/O port to display Neopixels red = [255, 0, 0] #define the red color mix yel = [255, 255, 0] #define the yellow color mix grn = [0, 255, 0] #define the green color mix off = [0, 0, 0] #define an off LED blank = off + off + off + off + off + off + off + off #create a set of OFF LEDs strip = red + red + red + red + yel + yel + grn + grn #create the battery status lights while (True): bat = TINK.getADC(0, 1) #read analog channel 1 #scale the data to an integer in the range of 0 through 7 temp = bat - 0.8 #we will only look at the range from 0.8 volts to 1.6 if (temp < 0): index = 0 #if the measured voltage is negative, set index to 0 else: #otherwise, convert the voltage to a list index index = int(temp * 10) if (index > 7): #limit the maximum index to 7 index = 7 batstrip = strip[0:3 * (index + 1)] + blank[0:3 * (8 - index)] #assembled string TINK.setRGBSTRING(0, 1, batstrip) #send string data to TINKERplate time.sleep(.5) #delay and repeat
def dout7Change(): #Callback function for digital output 7 if(doutCnt7.value=='SET'): TINK.setDOUT(0,7) else: TINK.clrDOUT(0,7) def dout8Change(): #Callback function for digital output 8 if(doutCnt8.value=='SET'): TINK.setDOUT(0,8) else: TINK.clrDOUT(0,8) #Initialize TINKERplate Digital I/O lines TINK.RESET(0) time.sleep(0.5) TINK.setMODE(0,1,'din') TINK.setMODE(0,2,'din') TINK.setMODE(0,3,'din') TINK.setMODE(0,4,'din') TINK.setMODE(0,5,'pwm') TINK.setMODE(0,6,'pwm') TINK.setMODE(0,7,'dout') TINK.setMODE(0,8,'dout') #Define the overall characteristics of our dashboard including size and background color app = App(title="TINKERplate Dashboard",bg="white",layout="grid",width=750,height=360) dashTitle=Text(app,text= "",width="fill",grid=[0,0,5,1]) #insert the callout image on the left side callOuts=Picture(app, grid=[0,1,3,3], image="Pinouts.jpg",width=400,height=271)
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
stringR = [0xFF,0x0,0x0] #Create a list of red LEDs patterns for i in range(3): stringR=stringR+stringR stringY = [0xFF,0xFF,0x00] #Create a list of yellow LEDs patterns for i in range(3): stringY=stringY+stringY stringG = [0x0,0xFF,0x00] #Create a list of green LEDs patterns for i in range(3): stringG=stringG+stringG stringO = [0x0,0x00,0x00] #Create a list of off LEDs patterns for i in range(3): stringO=stringO+stringO TINK.setDEFAULTS(0) #set all Digital I/O ports to their default states TINK.setMODE(0,1,'rgbled') #set the mode of Digital I/O port 1 to RGB LED TINK.setMODE(0,5,'dout') #set the mode of Digital I/O port 5 to digital output TINK.setMODE(0,78,'range') #set the mode of Digital I/O channel pair 78 to range dist=0.0 #initialize global variables bToggle=False blink=False alarm=False zone=0 while(True): #start repeating loop dist=TINK.getRANGEfast(0,78) #print(dist,zone) #uncomment for debugging try: blink=False #assume no blinking alarm=False #assume no alarm if(dist > dMax): #if measured distance is greater than dMax
import piplates.TINKERplate as TINK import time stringW = [0xFF,0xFF,0xFF] #Create a single full white LED pattern stringB = [0x0,0x0,0x0] #Create a single full off LED pattern TINK.setDEFAULTS(0) #set all Digital I/O ports to their default states TINK.setMODE(0,1,'rgbled') #set the mode of Digital I/O port 1 to RGB LED while(True): #start repeating loop ain=TINK.getADC(0,3) #read the voltage on Analog Input channel 3 k=(ain-0.3)/3.7 #subtract a 0.3V offset and scale result if(k<0): k=0 #clip lower limit to 0 if(k>1): k=1 #clip upper limit to 1 j=int(k*8.0+0.5) nlString=[] #Create empty list for i in range(j): nlString=nlString+stringW #populate 1st part of list with white LEDs for i in range(8-j): nlString=nlString+stringB #populate rest of list with OFF LEDs #print(j,nlString) #debug statement - uncomment to use #print(ain) #debug statement - uncomment to use TINK.setRGBSTRING(0,1,nlString) #send eight LED values to port 1 time.sleep(0.1) #sleep 100msec before repeating
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