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()
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 try: pz.setAllPixels(128, 0, 128) while True: change(1) pz.updatePixels() time.sleep(0.5) change(0) pz.updatePixels() time.sleep(0.5) except KeyboardInterrupt: print finally: pz.cleanup()
#shutslot=2 #doesn't change. set in intialisation shutcount = 0 #reset shutcount change(-1) #close mouth #now process brigthness level v = pz.readInput(0) # read adc value from audio input b = min(100, 5 * (abs(v - offset)) + 5) #calcuate next brigthness print(b) #print to terminal #check for offset calibration button trigger = pz.readInput(1) #check for button pressed if trigger == 0: #normally high: 0 if pushed offset = v #update offset value from current adc value #now adjust brightness if changed sufficiently if abs( blast - b ) > 10: #check if brightness has changed by at least 10 to reduce noise pz.setBrightness(b) #update brightness pz.updatePixels() #update all pixels blast = b #save brightness value time.sleep( 0.01 ) #short sleep to keep response time good, just enough to allow ctrl-C to get a look in except KeyboardInterrupt: print finally: pz.cleanup() #reset picon zero board
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()