コード例 #1
0
import time

d = '\u00b0'  #create the degree symbol

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

TINK.openMETER(1)  #Create a display meter on the screen
TINK.setTITLE('TINKERplate Demo')
TINK.setCOLOR((255, 0, 0))  #Set meter text color to RED to indicate warm range

while (True):  #start loop
    temp = TINK.getTEMP(0, 1)  #collect temperature data
    TINK.setMETER(temp, d + 'F', 'Temperature:')
    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
            TINK.setCOLOR(
                (0, 0,
                 255))  #Set meter text color to BLUE to indicate cool range
            print("Temperature:", temp,
                  ", Fan Off")  #indicate the state change
    else:
コード例 #2
0
import piplates.TINKERplate as TINK  #import TINKERplate module
import math  #import math module - needed for sine and pi
import time  #import the time module - needed for sleep

Mag=10
N=360
mColor=(255,255,0) #this tuple represents the color yellow
TINK.openMETER(4)  #create a panel meter with the default of a single line
TINK.setCOLOR(mColor)   #set meter color
TINK.setTITLE('Trigonometery Functions')    #Set meter title
while(True):  #Loop forever
    for i in range(N):   #do this 360 times
        TINK.setMETER(i,'degrees','Angle:',1)   #write angle to line 1
        val=math.sin(2*math.pi*i/360)           #calculate sine of angle
        TINK.setMETER(val,'','Sine:',2)         #write sine value to line 2
        val=math.cos(2*math.pi*i/360)           #calculate cosine of angle
        TINK.setMETER(val,'','Cosine:',3)       #write cosine value to line 3
        val=math.tan(2*math.pi*i/360)           #calculate tangent of angle
        TINK.setMETER(val,'','Tangent:',4)      #write tangent value to line 4        
        time.sleep(0.1)
    
    
コード例 #3
0
import piplates.TINKERplate as TINK
import time

#create battery state thresholds
VL = 1.2
VH = 1.4

TINK.openMETER(1)  #Create a panel meter on the screen

#Change window title:
TINK.setTITLE("TINKERplate Battery Tester")
#TINK.setCOLOR((255,0,0))   #start with red text

while (True):
    bat = TINK.getADC(0, 1)  #read analog chanel 1
    if (bat >= VH):
        TINK.setCOLOR((0, 255, 0))  #show green text
        TINK.setMETER(bat, 'Volts', 'GOOD', 1)  #indicate a GOOD battery
    if ((bat >= VL) and (bat < VH)):
        TINK.setCOLOR((255, 255, 0))  #show yellow text
        TINK.setMETER(bat, 'Volts', 'OK', 1)  #indicate an OK battery
    if (bat < VL):
        TINK.setCOLOR((255, 0, 0))  #show red text
        TINK.setMETER(bat, 'Volts', 'BAD', 1)  #indicate a BAD battery
    time.sleep(.5)  #delay and repeat