A remote controlled light using Blue Dot and a pimoroni blinkt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A remote controlled light using Blue Dot and a pimoroni blinkt. | |
# install packages - sudo pip3 install bluedot, blinkt, colorzero | |
import blinkt | |
from bluedot import BlueDot | |
from signal import pause | |
from colorzero import Color | |
from threading import Event | |
class BlinktDot(): | |
def __init__(self): | |
blinkt.set_brightness(0.05) | |
# event to keep track on when the blinkt is ready to be updated | |
self.blinkt_ready = Event() | |
self.blinkt_ready.set() | |
self.color = Color(0,0,255) | |
self.light_on = False | |
self.bd = BlueDot() | |
self.bd.when_double_pressed = self.on_off | |
self.bd.when_pressed = self.update_color | |
self.bd.when_moved = self.update_color | |
self.bd.visible = False | |
self.bd.border = True | |
def update_color(self, pos): | |
if self.light_on: | |
# only update the color if the blinkt is ready | |
if self.blinkt_ready.is_set(): | |
# calc color | |
hue = (pos.angle + 180) / 360 | |
self.color = Color(h=hue, s=1, v=1) | |
self.bd.color = self.color.rgb_bytes | |
self.set_pixels(*self.color.rgb_bytes) | |
def set_pixels(self, r, g, b): | |
self.blinkt_ready.clear() | |
for pixel in range(8): | |
blinkt.set_pixel(pixel, r, g, b) | |
blinkt.show() | |
self.blinkt_ready.set() | |
def clear(self): | |
self.blinkt_ready.clear() | |
blinkt.clear() | |
blinkt.show() | |
self.blinkt_ready.set() | |
def on_off(self, pos): | |
self.light_on = not self.light_on | |
if self.light_on: | |
self.bd.visible = True | |
self.set_pixels(*self.color.rgb_bytes) | |
else: | |
self.blinkt_ready.wait() | |
self.bd.visible = False | |
self.clear() | |
BlinktDot() | |
pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment