Esempio n. 1
0
class Light(object):
    def __init__(self):
        self.led_strip = LEDStrip(config.LED_COUNT)
        self.led_strip.set_master_brightness(0.9)
        self.led_strip.all_off()
        self.colors = {user['color']: False for user in config.USERS}

    def change_color(self, color, on):
        self.colors[color] = on
        self.update_light()

    def update_light(self):
        on_colors = [color for color, on in self.colors.items() if on]
        if len(on_colors) > 0:
            color = tuple(int(sum(x) / len(x)) for x in zip(*on_colors))
            self.led_strip.fill_rgb(*color)
        else:
            self.led_strip.fill_off()
        self.led_strip.update()