def blink(lock, stop): with lock: while not stop.is_set(): for i in range(phatbeat.CHANNEL_PIXELS): phatbeat.set_pixel(i, random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), channel=random.randint(0,1)) phatbeat.show() time.sleep(0.01)
def turnon_led(led, red, green, blue, channel_mode=False): if channel_mode == True: for channel in (0, 1): phatbeat.set_pixel(led, red, green, blue, channel=channel) else: phatbeat.set_pixel(led, red, green, blue) phatbeat.show()
def phatbeat_wait(): #global player #player = 'wait' phatbeat.clear() #phatbeat.set_all(0, 255, 0) #for channel in (0,1): phatbeat.set_pixel(0, 0, 255, 0, 0.1, 0) phatbeat.set_pixel(0, 0, 0, 255, 0.1, 1) phatbeat.show()
def rainbow(lock, stop): SPEED = 200 BRIGHTNESS = 64 SPREAD = 20 with lock: while not stop.is_set(): for x in range(phatbeat.CHANNEL_PIXELS): h = (time.time() * SPEED + (x * SPREAD)) % 360 / 360.0 r, g, b = [int(c*BRIGHTNESS) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)] phatbeat.set_pixel(x, r, g, b, channel=0) phatbeat.set_pixel(x, r, g, b, channel=1) phatbeat.show() time.sleep(0.001)
def rainbow(): SPEED = 300 BRIGHTNESS = 64 SPREAD = 20 #while True: for cycles in range(1, 200): for x in range(phatbeat.CHANNEL_PIXELS): h = (time.time() * SPEED + (x * SPREAD)) % 360 / 360.0 r, g, b = [int(c*BRIGHTNESS) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)] phatbeat.set_pixel(x, r, g, b, channel=0) phatbeat.set_pixel(x, r, g, b, channel=1) phatbeat.show() time.sleep(0.001) time.sleep(0.1) phatbeat.set_all(0,0,0)
def rainbow(): SPEED = 300 BRIGHTNESS = 64 SPREAD = 20 #while True: for cycles in range(1, 200): for x in range(phatbeat.CHANNEL_PIXELS): h = (time.time() * SPEED + (x * SPREAD)) % 360 / 360.0 r, g, b = [ int(c * BRIGHTNESS) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0) ] phatbeat.set_pixel(x, r, g, b, channel=0) phatbeat.set_pixel(x, r, g, b, channel=1) phatbeat.show() time.sleep(0.001) time.sleep(0.1) phatbeat.set_all(0, 0, 0)
def onoff(pin): global on print("OO Pressed") on = not on def set_channel_hue(channel, hue): r, g, b = [ int(x * 255) for x in colorsys.hsv_to_rgb(hue / 360.0, 1.0, 1.0) ] phatbeat.set_all(r, g, b, channel=channel) try: while True: if on: set_channel_hue(0, hue_l) set_channel_hue(1, hue_r) else: phatbeat.clear() phatbeat.show() time.sleep(0.01) except KeyboardInterrupt: pass
def pb_play_pause(pin): log(vlc.communicate("pause")) time.sleep(0.1) phatbeat.clear() phatbeat.show()
def clear(): stop_running_thread() phatbeat.clear() phatbeat.show()
def darken(): global brightness if brightness > 0.1: brightness -= 0.1 if brightness < 0.1: brightness = 0.1 phatbeat.set_brightness(brightness) phatbeat.show()
def brighten(): global brightness if brightness < 1: brightness += 0.1 if brightness > 1: brightness = 1 phatbeat.set_brightness(brightness) phatbeat.show()
def clear_leds(): phatbeat.clear() phatbeat.show()
def phatbeat_start(): phatbeat.clear() #phatbeat.set_all(255, 0, 255) for p in range(16): phatbeat.set_pixel(p, 200, 0, 255, 0.1) phatbeat.show()
def fast_forward(pin): print("Power On/Off pressed!") phatbeat.clear() phatbeat.show() sys.exit("exiting...")