class MoteLamp(BaseLamp): def __init__(self, channels=4, correction=[1., 1., 1.]): self.mote = Mote() for c in range(channels): self.mote.configure_channel(c + 1, 16, False) BaseLamp.__init__(self, correction=correction) self.channels = channels self.pixels = 16 for channel in range(self.channels): self.mote.configure_channel(channel + 1, self.pixels, False) self.width = self.channels self.height = self.pixels # Clear all pixels def clear(self): self.mote.clear() self.mote.show() def show(self): self.mote.show() # Set a single pixel def set_pixel(self, x, y, r, g, b): r, g, b = self.apply_correction(r, g, b) self.mote.set_pixel(x + 1, y, r, g, b) # Set all pixels to RGB def set_all(self, r, g, b): self.color = (r, g, b) r, g, b = self.apply_correction(r, g, b) self.mote.set_all(r, g, b) # Set maximum global brightness def set_brightness(self, val): val = int(val) if 0 <= val <= 255: self.mote.set_brightness( val / 255) # Set brightness through unicornhat library self.brightness = val # Log user-selected brightness to a variable self.mote.show() else: logging.error("Brightness must be between 0 and 255")
mote.clear() mote.show() # colours = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'] # iteration = 0 red = 255 green = 0 blue = 0 try: while True: if red > 0 and blue == 0: red -= 1 green += 1 if green > 0 and red == 0: green -= 1 blue += 1 if blue > 0 and green == 0: blue -= 1 red += 1 mote.set_all(red, green, blue, 0.5) mote.show() time.sleep(0.1) # iteration += 1 except KeyboardInterrupt: mote.clear() mote.show()
5) Carbon Arc bulb Press CTRL+C to exit and turn off. """) # main loop try: while True: # present choice options to user choice = input() choice = int(choice) if choice == 1: rgblist = candle elif choice == 2: rgblist = fortyw elif choice == 3: rgblist = hundredw elif choice == 4: rgblist = halogen elif choice == 5: rgblist = carbon mote.clear() mote.set_all(rgblist[0], rgblist[1], rgblist[2]) mote.show() time.sleep(1.0 / 60) except KeyboardInterrupt: mote.set_all(0, 0, 0) mote.show() mote.clear()
# v = gauss[x, y] # rgb = colorsys.hsv_to_rgb(h, s, v) # r, g, b = [int(255.0 * i) for i in rgb] # mote.set_pixel(1, x, r, g, b) # mote.set_pixel(2, x, r, g, b) # mote.set_pixel(3, x, r, g, b) # mote.set_pixel(4, x, r, g, b) # mote.show() # mote.show() # time_sleep = 0.05 # GAMING ON elif gaming_enabled == True and active_desk: print("GAMING MODE") gaming_mode(mote) time_sleep = 0.1 # NORMAL LAMP elif (distance_in_cm < MAX_ON and not gaming_enabled) or active_desk: # on the desk print("NORMAL LAMP") mote.set_all(255, 141, 41) mote.show() time_sleep = 1 # GAMING OFF elif (gaming_enabled and not active_desk) or not gaming_enabled: mote.clear() mote.show() time.sleep(time_sleep)
def handle_key(index, state): global brightlist if state and brightlist == off: brightlist = quarter keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2]) elif state and brightlist == quarter: brightlist = half keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2]) elif state and brightlist == half: brightlist = threequarter keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2]) elif state and brightlist == threequarter: brightlist = full keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2]) elif state and brightlist == full: brightlist = off keybow.set_led(index, brightlist[0], brightlist[1], brightlist[2]) return brightlist # main loop -- TODO function that takes current state + dictionary and returns next state while True: mote.clear() mote2.clear() mote.set_all(rgblist[0], rgblist[1], rgblist[2]) mote2.set_all(brightlist[0], brightlist[1], brightlist[2]) mote.show() mote2.show() keybow.show() time.sleep(0.2)
#!/usr/bin/env python import time from mote import Mote rgb = (128, 0, 0) mote = Mote() mote.configure_channel(1, 16, False) mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) while True: r, g, b = rgb mote.set_all(r, g, b) mote.show() time.sleep(1) rgb = (g, b, r)