def backlight_magnitudes(self, magnitudes): brightness = sum(magnitudes[:3]) / 3.0 colours = [round(c * brightness) for c in COLOUR_RED] backlight.single_rgb(0, colours[0], colours[1], colours[2]) brightness = sum(magnitudes[3:5]) / 2.0 colours = [round(c * brightness) for c in COLOUR_YELLOW] backlight.single_rgb(1, colours[0], colours[1], colours[2]) brightness = sum(magnitudes[5:8]) / 3.0 colours = [round(c * brightness) for c in COLOUR_GREEN] backlight.single_rgb(2, colours[0], colours[1], colours[2]) brightness = sum(magnitudes[8:11]) / 3.0 colours = [round(c * brightness) for c in COLOUR_CYAN] backlight.single_rgb(3, colours[0], colours[1], colours[2]) brightness = sum(magnitudes[11:13]) / 2.0 colours = [round(c * brightness) for c in COLOUR_BLUE] backlight.single_rgb(4, colours[0], colours[1], colours[2]) brightness = sum(magnitudes[13:16]) / 3.0 colours = [round(c * brightness) for c in COLOUR_MAGENTA] backlight.single_rgb(5, colours[0], colours[1], colours[2])
[0,0,0,0,0,0,0,0] ] def tidyup(): backlight.off() lcd.clear() def get_anim_frame(char,fps): return char[ int(round(time.time()*fps) % len(char)) ] backlight.graph_off() backlight.off() lcd.set_cursor_position(0,0) lcd.write(chr(0) * 16) lcd.set_cursor_position(0,1) lcd.write(chr(0) * 16) lcd.set_cursor_position(0,2) lcd.write(chr(0) * 16) time.sleep(1) for x in range(0,255,5): backlight.single_rgb(3,x,x,x) atexit.register(tidyup) while True: lcd.create_char(0,get_anim_frame(rain,20)) time.sleep(0.1) #signal.pause()
backlight.off() elif command == 'setBrightnessOfLed': backlight.set(parameters['ledIndex'], parameters['brightness']) elif command == 'setToHue': backlight.hue(parameters['hue']) elif command == 'setLeftToHue': backlight.left_hue(parameters['hue']) elif command == 'setMiddleToHue': backlight.mid_hue(parameters['hue']) elif command == 'setRightToHue': backlight.right_hue(parameters['hue']) elif command == 'setToRGB': backlight.rgb(parameters['red'], parameters['green'], parameters['blue']) elif command == 'setZoneToRGB': backlight.single_rgb(parameters['zoneIndex'], parameters['red'], parameters['green'], parameters['blue']) elif command == 'setLeftToRGB': backlight.left_rgb(parameters['red'], parameters['green'], parameters['blue']) elif command == 'setMiddleToRGB': backlight.mid_rgb(parameters['red'], parameters['green'], parameters['blue']) elif command == 'setRightToRGB': backlight.right_rgb(parameters['red'], parameters['green'], parameters['blue']) elif component == 'BarGraph': if command == 'turnOff': backlight.graph_off() elif command == 'setByPercentage': backlight.set_graph(float(parameters['percentage']) / 100) elif command == 'setBrightness':
return new_index @touch.on(touch.BUTTON) def handle_button_tap(ch, evt): displayotronhat.print_string('PARTY TIME!!1') try: displayotronhat.print_string('11 Nov 2017') displayotronhat.print_string('Moscow +4 °C') displayotronhat.print_string('1 BTC = $ 1234') offset = 0 while True: backlight.single_rgb(get_new_index(0, offset), 255, 0, 0) backlight.single_rgb(get_new_index(1, offset), 255, 255, 0) backlight.single_rgb(get_new_index(2, offset), 128, 255, 0) backlight.single_rgb(get_new_index(3, offset), 0, 128, 255) backlight.single_rgb(get_new_index(4, offset), 127, 0, 255) backlight.single_rgb(get_new_index(5, offset), 128, 128, 128) # backlight.set_graph(0.2 * offset) sleep(0.02) if offset == 5: offset = 0 else: offset += 1 except KeyboardInterrupt: backlight.off()
if command == 'turnOff': backlight.off() elif command == 'setBrightnessOfLed': backlight.set(parameters['ledIndex'], parameters['brightness']) elif command == 'setToHue': backlight.hue(parameters['hue']) elif command == 'setLeftToHue': backlight.left_hue(parameters['hue']) elif command == 'setMiddleToHue': backlight.mid_hue(parameters['hue']) elif command == 'setRightToHue': backlight.right_hue(parameters['hue']) elif command == 'setToRGB': backlight.rgb(parameters['red'], parameters['green'], parameters['blue']) elif command == 'setZoneToRGB': backlight.single_rgb(parameters['zoneIndex'], parameters['red'], parameters['green'], parameters['blue']) elif command == 'setLeftToRGB': backlight.left_rgb(parameters['red'], parameters['green'], parameters['blue']) elif command == 'setMiddleToRGB': backlight.mid_rgb(parameters['red'], parameters['green'], parameters['blue']) elif command == 'setRightToRGB': backlight.right_rgb(parameters['red'], parameters['green'], parameters['blue']) elif component == 'BarGraph': if command == 'turnOff': backlight.graph_off() elif command == 'setByPercentage': backlight.set_graph(float(parameters['percentage']) / 100) elif command == 'setBrightness': backlight.graph_set_led_duty(parameters['minimumBrightness'], parameters['maximumBrightness']) elif command == 'setEnabledStateOfLed': backlight.graph_set_led_polarity(parameters['ledIndex'], 0b00000000)