def update(self, pixel_value): is_in_combat = pixel_value == 1 print("In Combat: {}".format(is_in_combat)) if (self.is_in_combat_prev == is_in_combat): time.sleep(0.1) return if (is_in_combat): self.light.set_color(adjust_brightness(RED, 0.35), rapid=True) time.sleep(0.05) self.light.set_waveform(False, adjust_brightness(RED, 0.5), 2000, 100, 1, 1, rapid=True) # period, cycles, duty_cycle, waveform else: self.light.set_color(adjust_brightness(RED, 0), rapid = True, duration=1000) self.is_in_combat_prev = is_in_combat time.sleep(0.5)
def update(self, pixel_value): energy_fraction = pixel_value / 255.0 print("Energy: {:.2f}".format(energy_fraction)) if (energy_fraction != self.current_energy): self.light.set_color(adjust_brightness(YELLOW, energy_fraction), rapid=True) self.current_energy = energy_fraction time.sleep(0.1)
def update(self, pixel_value): # The pixel value can go over 5 in edge cases when the user is tabbed out. # Cap the value at the max combo points. combo_points = min(pixel_value, self.MAX_COMBO_POINTS) if (combo_points == self.current_combo_points): time.sleep(0.1) return self.current_combo_points = combo_points print("Combo: {}".format(combo_points)) color = adjust_brightness(RED, combo_points / self.MAX_COMBO_POINTS) num_zones_to_fill = self._get_num_zones_to_fill(combo_points) if (num_zones_to_fill > 0): self.light.set_zone_color(0, num_zones_to_fill - 1, color, rapid=True, apply=False) if (combo_points < self.MAX_COMBO_POINTS): self.light.set_zone_color(num_zones_to_fill, self.number_of_zones, adjust_brightness(color, 0), rapid=True, apply=True) # Turn off the other lights if (combo_points == self.MAX_COMBO_POINTS): try: self.light.set_color(color) except: print("Failed to set color. Trying with rapid=True") self.light.set_color(color, rapid=True) # Max of 20 Hz recommended to LIFX. time.sleep(0.05) self.light.set_waveform( False, adjust_brightness(color, 0.5), 1000, 100, 1, 1, rapid=True) # period, cycles, duty_cycle, waveform time.sleep(0.25)
def update(self, pixel_value): rage_fraction = pixel_value / 255.0 print("Rage: {:.2f}".format(rage_fraction)) if (rage_fraction != self.current_rage): # Experimenting with setting the light three times for # reliability. for i in range(3): self.light.set_color(adjust_brightness(RED, rage_fraction), rapid=True) # Max 20 Hz recommended by LIFX time.sleep(0.05) self.current_rage = rage_fraction time.sleep(0.1)
def update(self, pixel_value): hp_fraction = pixel_value / 255.0 if (hp_fraction == self.current_hp): time.sleep(0.25) return if (hp_fraction > 0.5): color = interpolate(YELLOW, GREEN, (hp_fraction - 0.5) / 0.5) elif (hp_fraction > 0.001): color = interpolate(RED, YELLOW, hp_fraction / 0.5) print(color) else: color = BLUE # Experimenting with setting the light three times for # reliability. for i in range(3): self.light.set_color(adjust_brightness(color, 1), rapid=True) # Max 20 Hz recommended by LIFX time.sleep(0.05) print("HP: {:.2f}".format(hp_fraction)) self.current_hp = hp_fraction
import time from lifxlan import LifxLAN from lifxlan import GREEN, YELLOW, RED, BLUE from color import interpolate, adjust_brightness # connect to lifx MAX_CONNECTION_RETRIES = 5 lifx = LifxLAN(1) print("Connecting...") light = None for i in range(MAX_CONNECTION_RETRIES): try: light = lifx.get_device_by_name("mini_1") #light = lifx.get_multizone_lights()[0] break except: print("Retrying...") time.sleep(1) if light is None: raise Exception("Failed to connect to LIFX device! Please try again.") print("Connected!") # set light to blue color = RED #light.set_color() light.set_color(adjust_brightness(color, 1), rapid=True)