def adjust(brightness=100, speed=100): print('Main | Adjusting settings. Brightness: %d Speed %dms' % (brightness, speed * (RESPONSE_RATE_MS / 1000))) global SPEED SPEED = speed leds.changeBrightness(brightness / 100.0) leds.show()
def __fadeColors(self, currentColor, targetColor): print('Fade from %s to %s' % (currentColor, targetColor)) colors = self.__colorsBetween(currentColor, targetColor, 240) colors.insert(0, currentColor) colors.append(targetColor) for color in colors: print(color) leds.changeColor(color) leds.show()
def EXECUTE(requestId, userId, data): print('PRE-EXECUTE: State: %s Brightness: %s Color: %s Mode: %s' % (cache.get(cache.STATE), cache.get(cache.BRIGHTNESS), cache.get(cache.COLOR), cache.get(cache.MODE))) for command in data['inputs'][0]['payload']['commands']: for execute in command['execution']: if ('OnOff' in execute['command']): if execute['params']['on']: leds.turnOn() else: leds.turnOff() elif ('BrightnessAbsolute' in execute['command']): leds.changeBrightness(int(execute['params']['brightness'])) elif ('ColorAbsolute' in execute['command']): leds.changeColor( (execute['params']['color']['spectrumHSV']['hue'] / 360.0, execute['params']['color']['spectrumHSV'] ['saturation'], execute['params']['color']['spectrumHSV']['value']), True) print('Ran %s' % execute['command']) leds.show() print('POST-EXECUTE: State: %s Brightness: %s Color: %s Mode: %s' % (cache.get(cache.STATE), cache.get(cache.BRIGHTNESS), cache.get(cache.COLOR), cache.get(cache.MODE))) return { 'requestId': requestId, 'payload': { 'commands': [{ 'ids': ['1'], 'status': 'SUCCESS', 'states': { 'online': True, 'on': cache.get(cache.STATE), 'brightness': cache.get(cache.BRIGHTNESS), 'spectrumHSV': cache.get(cache.COLOR) } }] } }
def random(self): for i in range(leds.count): color = self.data['colors'][random.randint( 0, (len(self.data['colors']) - 1))] leds.changeColor((int(color[0]), int(color[1]), int(color[2])), i) leds.show()
def off(self): leds.blank() leds.show()
def color(self): leds.changeColor( [int(self.data['g']), int(self.data['r']), int(self.data['b'])]) leds.show()