def showFace(data, Red, Green, Blue): for i in range(numPixels): if (data[i] > 0): pz.setPixel(i, Red, Green, Blue, False) else: pz.setPixel(i, 0, 0, 0, False) pz.updatePixels()
def next_color(): # RAINBOW hue = int(time.time() * 100) % 360 for x in range(16): offset = x * self.spacing h = ((hue + offset) % 360) / 360.0 r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)] pz.setPixel(x, r, g, b) pz.updatePixels()
def next_color(): delta = (time.time() - start_time) * 16 # Triangle wave, a snappy ping-pong effect offset = int(abs((delta % 16) - 8)) for i in range(8): pz.setPixel(i, 0, self.REDS[offset + i], 0) pz.updatePixels()
def next_color(self): delta = (time.time() - self.start_time) * 8 print("DELTA: ") print(delta) # Triangle wave, a snappy ping-pong effect offset = int(abs((delta % 16) - 8)) print("OFFSET: ") print(offset) for i in range(16): print("I: ") print(i) pz.setPixel(i , 0, self.REDS[offset + i], 0) pz.updatePixels()
def distance2Pixel(dist): pz.setAllPixels(0, 0, 0) if (dist > 80): dist = 80 if (dist < 15): green = 0 red = 255 blue = 0 elif (dist < 30): green = 165 red = 255 blue = 0 else: green = 255 red = 0 blue = 0 for i in range(8 - dist / 10): pz.setPixel(i, red, green, blue)
from __future__ import absolute_import import piconzero as pz, time pz.setInputConfig(0, 1) # set input 0 to Analog pz.setOutputConfig(0, 1) # set output 0 to PWM pz.setOutputConfig(2, 2) # set output 2 to Servo pz.setOutputConfig(5, 3) # set output 5 to WS2812 while True: ana0 = pz.readInput(0) pz.setOutput(0, ana0/10) pz.setPixel(0,0,0,ana0/4) pz.setOutput(2, int(ana0/7)) time.sleep(0.1) # this makes 11 active lines, but can be removed
#! /usr/bin/env python #testLedNumbers.py # Testing McRoboFace led positions. # requires picon zero hardware plus software library import piconzero as pz, time pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 (code 3) try: while True: for i in xrange(0, 17): pz.setPixel(i, 0, 0, 255) time.sleep(0.5) pz.setAllPixels(0, 0, 0) time.sleep(0.5) except KeyboardInterrupt: print finally: pz.cleanup() #reset picon zero board
def setNeoPixel(pixel, rgb): r, g, b = rgb pz.setPixel(pixel, int(r), int(g), int(b))
def change(t): #parameter = 1 to open mouth anything else to close it #False parameter so all updates done together once set up, when brightness changes pz.setPixel(0, 128, 0, 128, False) #end of mouth always this colour pz.setPixel(5, 128, 0, 128, False) #other end of mouth if t == 1: #going for open mouth for i in xrange(1, 5): #mouth set pixels for open state pz.setPixel(i, 128, 0, 128, False) pz.setPixel(i + 5, 128, 0, 128, False) for i in xrange(10, 14): #pixels for closed mouth turned off pz.setPixel(i, 0, 0, 0, False) else: #going for closed mouth for i in xrange(1, 5): #mouth pz.setPixel(i, 0, 0, 0, False) pz.setPixel(i + 5, 0, 0, 0, False) for i in xrange(10, 14): #pixels for closed mouth turned on pz.setPixel(i, 128, 0, 128, False) return
lastPix = 0 numpixels = 8 pz.init() pz.setInputConfig(0, 1) # set input 0 to Analog pz.setOutputConfig(0, 1) # set output 0 to PWM pz.setOutputConfig(2, 2) # set output 2 to Servo pz.setOutputConfig(5, 3) # set output 5 to WS2812 rev = pz.getRevision() print(rev[0], rev[1]) try: while True: ana0 = pz.readInput(0) #print ana0, int(0.5 + ana0/113.7), int(ana0/7) pz.setOutput(0, ana0 / 10) #setMotor(0, ana0/10) if (int(0.4 + ana0 * numpixels / 1000) != lastPix): lastPix = int(0.5 + ana0 * numpixels / 1000) for i in range(64): if i < lastPix: pz.setPixel(i, 0, 0, 255, False) else: pz.setPixel(i, 0, 0, 0, False) pz.updatePixels() pz.setOutput(2, int(ana0 / 7)) time.sleep(0.1) except KeyboardInterrupt: print() finally: pz.cleanup()
import piconzero as pz, time pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 pz.setBrightness(15) delay = 0.1 colour = [0,255,125] # colour format of LEDs 0 to 7 is G R B # Set rear light to Red for posistion in range(4, 8, 1): pz.setPixel(posistion, 0, 255, 0) try: while True: for posistion in range(0,4,1): pz.setPixel(posistion, colour[0], colour[1], colour[2]) time.sleep(delay) for off in range(0, 4, 1): pz.setPixel(off, 0,0,0) time.sleep(delay) for posistion in range(2, 0, -1): pz.setPixel(posistion, colour[0], colour[1], colour[2]) time.sleep(delay) for off in range(0, 4, 1): pz.setPixel(off, 0, 0, 0) time.sleep(delay) except KeyboardInterrupt: print ('finished') finally: pz.cleanup()
import piconzero as pz, time pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 pz.setBrightness(15) delay = 0.1 colour = [0, 255, 125] # colour format of LEDs 0 to 7 is G R B # Set rear light to Red for posistion in range(4, 8, 1): pz.setPixel(posistion, 0, 255, 0) try: while True: for posistion in range(0, 4, 1): pz.setPixel(posistion, colour[0], colour[1], colour[2]) time.sleep(delay) for off in range(0, 4, 1): pz.setPixel(off, 0, 0, 0) time.sleep(delay) for posistion in range(2, 0, -1): pz.setPixel(posistion, colour[0], colour[1], colour[2]) time.sleep(delay) for off in range(0, 4, 1): pz.setPixel(off, 0, 0, 0) time.sleep(delay) except KeyboardInterrupt: print('finished') finally: pz.cleanup()
pz.setPixel(i, 128, 0, 128, False) pz.setPixel(i + 5, 128, 0, 128, False) for i in xrange(10, 14): #pixels for closed mouth turned off pz.setPixel(i, 0, 0, 0, False) else: #going for closed mouth for i in xrange(1, 5): #mouth pz.setPixel(i, 0, 0, 0, False) pz.setPixel(i + 5, 0, 0, 0, False) for i in xrange(10, 14): #pixels for closed mouth turned on pz.setPixel(i, 128, 0, 128, False) return try: pz.setAllPixels(128, 0, 128) #set an initial pixel state pz.setPixel(15, 0, 255, 0, False) #eye pz.setPixel(16, 0, 255, 0) #other eye pz.setPixel(14, 0, 0, 255) #nose while True: #adjust counters depending upon whether mouth open or closed if openFlag == 1: opencount += 1 #increase count of number of cycles mouth is open else: shutcount += 1 #increase count of number of cycles mouth is closed if (b > threshold) and (shutcount > shutslot) and ( openFlag == 0): #open mouth triggered by audio opencount = 0 #reset count to 0 openslot = int(b / 10) #set openslot cycles according to brightness openFlag = 1 #opening so set flag
import piconzero as pz, time pz.setInputConfig(0, 1) # set input 0 to Analog pz.setOutputConfig(0, 1) # set output 0 to PWM pz.setOutputConfig(2, 2) # set output 2 to Servo pz.setOutputConfig(5, 3) # set output 5 to WS2812 while True: ana0 = pz.readInput(0) pz.setOutput(0, ana0/10) pz.setPixel(0,0,0,ana0/4) pz.setOutput(2, int(ana0/7)) time.sleep(0.1) # this makes 11 active lines, but can be removed
numpixels = 8 pz.init() pz.setInputConfig(0, 1) # set input 0 to Analog pz.setOutputConfig(0, 1) # set output 0 to PWM pz.setOutputConfig(2, 2) # set output 2 to Servo pz.setOutputConfig(5, 3) # set output 5 to WS2812 rev = pz.getRevision() print rev[0], rev[1] try: while True: ana0 = pz.readInput(0) #print ana0, int(0.5 + ana0/113.7), int(ana0/7) pz.setOutput(0, ana0/10) #setMotor(0, ana0/10) if (int(0.4 + ana0*numpixels/1000) != lastPix): lastPix = int(0.5 + ana0*numpixels/1000) for i in range (64): if i < lastPix: pz.setPixel(i, 0, 0, 255, False) else: pz.setPixel(i, 0, 0, 0, False) pz.updatePixels() pz.setOutput(2, int(ana0/7)) time.sleep(0.1) except KeyboardInterrupt: print finally: pz.cleanup()