def report_status(): pixel_status = [] for i in range(NUM_PIXELS): pixel_status.append( dict(Pixel=i, Status=dict( zip(["Red", "Green", "Blue", "Brightness"], get_pixel(i))))) data = {"status": 200, "message": pixel_status} return jsonify( data ) # This ruins the order of keys for humans. JSON doesn't care, and neither do we.
def set_pixel_if_blank(led_index, red_on, green_on, blue_on, brightness_on): [red_current, green_current, blue_current, _] = get_pixel(led_index) if red_current == 0 and green_current == 0 and blue_current == 0: set_pixel(led_index, red_on, green_on, blue_on, brightness_on)
def ledGet(p): return blinkt.get_pixel(p)
def getColor() : status = blinkt.get_pixel(0) return status
TIME_SLEEP = 0.04 # seconds (0.04 works well) PIXELS = blinkt.NUM_PIXELS # usually 8, can use fewer if you like! blinkt.clear # make all pixels blank / black blinkt.set_brightness(BRIGHTNESS) brightpixel = -1 direction = 1 print('Hello Michael.\nHow are you today?') while True: # decay all pixels for x in range(PIXELS): pixel = blinkt.get_pixel(x) # format is [ r, g, b, brightness? ] blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0) # brightpixel should move back and forth all the pixels, # in a ping-pong, triangle wave. Not (co)sine. brightpixel += direction if brightpixel >= PIXELS - 1: brightpixel = PIXELS - 1 direction = - abs(direction) if brightpixel <= 0: brightpixel = 0 direction = abs(direction) blinkt.set_pixel(brightpixel, MAX_COLOUR, 0, 0)
def getBrightness(self): r, g, b, brightness = blinkt.get_pixel(0) return brightness
def getColor(self): r, g, b, brightness = blinkt.get_pixel(0) return r, g, b
def HandleFlash(self, led, color, time_ms): previous = blinkt.get_pixel(led) self.HandleOn(led, color) time.sleep(time_ms / 1000) self.HandleOn(led, previous[:3]) # first 3 items are the color values