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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
         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
Ejemplo n.º 4
0
import piplates.TINKERplate as TINK
import time

string0 = [0xFF, 0xFF, 0xFF]  #Create a single full white 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
    print(ain)  #debug statement - uncomment to use
    string2 = [(x * k) // 1 for x in string0
               ]  #scale the values in string0 from 0 through 255
    print(string2)  #debug statement - uncomment to use
    #create the full, 8 channel RGB LED string:
    string1 = string2 + string2 + string2 + string2 + string2 + string2 + string2 + string2
    TINK.setRGBSTRING(0, 1, string1)  #send eight LED claues to port 1
    time.sleep(0.1)  #sleep 100msec before repeating