def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights,False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selected {}".format(strip.get_label())) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_count = len(all_zones) delay = 0.06 snake_color = RED background_color = GREEN snake_size = zone_count/2 # length of snake in zones tail = 0 head = snake_size - 1 try: while True: # Case 1: Snake hasn't wrapped around yet if head > tail: if tail > 0: strip.set_zone_color(0, tail-1, background_color, 0, True, 0) strip.set_zone_color(tail, head, snake_color, 0, True, 0) if head < zone_count - 1: strip.set_zone_color(head+1, zone_count-1, background_color, 0, True, 1) # Case 2: Snake has started to wrap around else: if head > 0: strip.set_zone_color(0, head-1, snake_color, 0, True, 0) strip.set_zone_color(head, tail, background_color, 0, True, 0) if tail < zone_count - 1: strip.set_zone_color(tail+1, zone_count-1, snake_color, 0, True, 1) # update indices for the snake's head and tail tail = (tail+1) % zone_count head = (head+1) % zone_count sleep(delay) except KeyboardInterrupt: strip.set_zone_colors(original_zones, 500, True)
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights, False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_buff = all_zones ignore = [-1] try: while True: for i in range(12): z = -1 while z in ignore: z = randrange(0, len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 2000, k strip.set_zone_color(z, z, [h, s, 40000, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) for i in range(12): z = -1 while z in ignore: z = randrange(0, len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 65535, k strip.set_zone_color(z, z, [h, s, 65535, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) #sleep(0.25) ignore = [-1] except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True)
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights,False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_buff = all_zones ignore = [-1] try: while True: for i in range(12): z = -1 while z in ignore: z = randrange(0,len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 2000, k strip.set_zone_color(z, z, [h, s, 40000, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) for i in range(12): z = -1 while z in ignore: z = randrange(0,len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 65535, k strip.set_zone_color(z, z, [h, s, 65535, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) #sleep(0.25) ignore = [-1] except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True)
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights, False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = all_zones dim_zones = [] bright_zones = [] for [h, s, v, k] in all_zones: dim_zones.append((h, s, 20000, k)) bright_zones.append((h, s, 65535, k)) try: print("Breathing...") while True: strip.set_zone_colors(bright_zones, 2000, True) sleep(2) strip.set_zone_colors(dim_zones, 2000, True) sleep(2) except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True) else: print("No lights with MultiZone capability detected.")
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights,False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = all_zones dim_zones = [] bright_zones = [] for [h,s,v,k] in all_zones: dim_zones.append((h,s,20000,k)) bright_zones.append((h,s,65535,k)) try: print("Breathing...") while True: strip.set_zone_colors(bright_zones, 2000, True) sleep(2) strip.set_zone_colors(dim_zones, 2000, True) sleep(2) except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True) else: print("No lights with MultiZone capability detected.")
def main(): # Find the lights (well, assume they exist or otherwise crash :)))) lifx = LifxLAN(int(1), False) multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: # Get the lights n stuff strip = multizone_lights[0] all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_count = len(all_zones) devices = lifx.get_lights() bulb = devices[0] original_power = bulb.get_power() bulb.set_power("on") # Snake size snake_size = zone_count / 32 # length of snake in zones tail = 0 head = snake_size - 1 # COLOURSSS !!!!! randomColours = [CYAN, GREEN, ORANGE, PINK, PURPLE, YELLOW, BLUE] snake_color = WHITE background_color = RED try: while True: # Keyboard triggers for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() elif event.key == pygame.K_SPACE: print("SPACE") check(WINNER_TILE_FROM, WINNER_TILE_TO, tail) # Interval of when the snake should move time.sleep(WAIT) # Case 1: Snake hasn't wrapped around yet if head > tail: if tail > 0: strip.set_zone_color(0, tail - 1, background_color, 0, True, 0) strip.set_zone_color(tail, head, snake_color, 0, True, 0) if head < zone_count - 1: strip.set_zone_color(head + 1, zone_count - 1, background_color, 0, True, 1) # Case 2: Snake has started to wrap around else: if head > 0: strip.set_zone_color(0, head - 1, snake_color, 0, True, 0) strip.set_zone_color(head, tail, background_color, 0, True, 0) if tail < zone_count - 1: strip.set_zone_color(tail + 1, zone_count - 1, snake_color, 0, True, 1) # update indices for the snake's head and tail tail = (tail + 1) % zone_count head = (head + 1) % zone_count if tail >= WINNER_TILE_FROM and tail <= WINNER_TILE_TO: strip.set_zone_color(WINNER_TILE_FROM, WINNER_TILE_TO, random.choice(randomColours), 20, True, 1) background_color = random.choice(randomColours) else: strip.set_zone_color(WINNER_TILE_FROM, WINNER_TILE_TO, background_color, 0, True, 1) except KeyboardInterrupt: return
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights, False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selected {}".format(strip.get_label())) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_count = len(all_zones) print(zone_count) delay = 0.06 snake_color = RED background_color = GREEN snake_size = zone_count / 2 # length of snake in zones tail = 0 head = snake_size - 1 try: while True: # Case 1: Snake hasn't wrapped around yet if head > tail: if tail > 0: strip.set_zone_color(0, tail-1, background_color, 0, True, 0) strip.set_zone_color(tail, head, snake_color, 0, True, 0) if head < zone_count - 1: strip.set_zone_color(head+1, zone_count-1, background_color, 0, True, 1) # Case 2: Snake has started to wrap around else: if head > 0: strip.set_zone_color(0, head-1, snake_color, 0, True, 0) strip.set_zone_color(head, tail, background_color, 0, True, 0) if tail < zone_count - 1: strip.set_zone_color(tail+1, zone_count-1, snake_color, 0, True, 1) # update indices for the snake's head and tail tail = (tail+1) % zone_count head = (head+1) % zone_count sleep(delay) except KeyboardInterrupt: strip.set_zone_colors(original_zones, 500, True)
from lifxlan import LifxLAN from plugins.hp_handler import HpHandler from plugins.energy_handler import EnergyHandler from plugins.combo_points_handler import ComboPointsHandler from plugins.rage_handler import RageHandler from statcast_runner import StatcastRunner MAX_CONNECTION_RETRIES = 5 lifx = LifxLAN(1) print("Connecting...") light = None for i in range(MAX_CONNECTION_RETRIES): try: 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!") statcast_runner = StatcastRunner( light, ScreenReader(pixel_value_to_mode_dict = { 0: Mode.HP, 1: Mode.COMBO_POINTS,
def lightDiscovery(): # Discover lights print("Discovering lights...") lifx = LifxLAN(None, False) lifx.set_power_all_lights("on", duration=1000, rapid=True) # Get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selected {}".format(strip.get_label())) # Light Stuff all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_count = len(all_zones) # Options colour_options = [ BLUE, COLD_WHITE, CYAN, GOLD, GREEN, ORANGE, PINK, PURPLE, RED, WARM_WHITE, WHITE, YELLOW ] starting_color = YELLOW current_color = starting_color background_color = WHITE user_triggered_transition_duration = 100 # User Stuff user_zone_size = zone_count / 6 # length of snake in zones current_user_zone_start = (zone_count / 2) - (user_zone_size / 2) current_user_zone_end = current_user_zone_start + user_zone_size try: while True: strip.set_color(background_color) strip.set_zone_color(current_user_zone_start, current_user_zone_end, current_color, 500) def on_press( key ): # The function that's called when a key is released nonlocal current_user_zone_start nonlocal current_user_zone_end nonlocal current_color nonlocal background_color nonlocal user_zone_size print("-- key: {0}.".format(key)) # Get new colour new_color = random.choice(colour_options) while new_color == current_color: new_color = random.choice(colour_options) # If up key is pressed increase the snake size by 1 if key == Key.up: user_zone_size = min(user_zone_size + 1, zone_count - 1) current_user_zone_end = current_user_zone_start + user_zone_size strip.set_zone_color( current_user_zone_start, current_user_zone_end, current_color, user_triggered_transition_duration) strip.set_zone_color( 0, current_user_zone_start - 1, background_color, user_triggered_transition_duration) strip.set_zone_color( current_user_zone_end + 1, zone_count, background_color, user_triggered_transition_duration) # If down key is pressed decrease the snake size by 1 if key == Key.down: user_zone_size = max(user_zone_size - 1, 1) current_user_zone_end = current_user_zone_start + user_zone_size strip.set_zone_color( current_user_zone_start, current_user_zone_end, current_color, user_triggered_transition_duration) strip.set_zone_color( 0, current_user_zone_start - 1, background_color, user_triggered_transition_duration) strip.set_zone_color( current_user_zone_end + 1, zone_count, background_color, user_triggered_transition_duration) # If left arrow key is pressed move the snake left 1 if key == Key.left: current_user_zone_start = min( current_user_zone_start + 1, zone_count) current_user_zone_end = min(current_user_zone_end + 1, zone_count) strip.set_zone_color( current_user_zone_start, current_user_zone_end, current_color, user_triggered_transition_duration) strip.set_zone_color( 0, max(current_user_zone_start - 1, 0), background_color, user_triggered_transition_duration) strip.set_zone_color( current_user_zone_end + 1, zone_count, background_color, user_triggered_transition_duration) # If right arrow key is pressed move the snake right 1 if key == Key.right: current_user_zone_start = max( current_user_zone_start - 1, 0) current_user_zone_end = max(current_user_zone_end - 1, 0) strip.set_zone_color( current_user_zone_start, current_user_zone_end, current_color, user_triggered_transition_duration) strip.set_zone_color( 0, max(current_user_zone_start - 1, 0), background_color, user_triggered_transition_duration) strip.set_zone_color( current_user_zone_end + 1, zone_count, background_color, user_triggered_transition_duration) def on_release( key ): # The function that's called when a key is pressed nonlocal current_user_zone_start nonlocal current_user_zone_end nonlocal current_color nonlocal background_color # Get new colour new_color = random.choice(colour_options) while new_color == current_color: new_color = random.choice(colour_options) # If space key is pressed change the snake colour if key == Key.space: print( "Space pressed, new color: {0}".format(new_color)) strip.set_zone_color(current_user_zone_start, current_user_zone_end, new_color, 500) current_color = new_color # strip.set_color(new_color) # If down right shift key is pressed change the background colour if key == Key.shift_r: strip.set_zone_color(0, current_user_zone_start, new_color, 1000) strip.set_zone_color(current_user_zone_end, zone_count, new_color, 1000) background_color = new_color with Listener(on_press=on_press, on_release=on_release ) as listener: # Create an instance of Listener listener.join( ) # Join the listener thread to the main thread to keep waiting for keys # try: # while True: # # Case 1: Snake hasn't wrapped around yet # if head > tail: # if tail > 0: # strip.set_zone_color(0, tail-1, background_color, 0, True, 0) # strip.set_zone_color(tail, head, snake_color, 0, True, 0) # if head < zone_count - 1: # strip.set_zone_color(head+1, zone_count-1, background_color, 0, True, 1) # # Case 2: Snake has started to wrap around # else: # if head > 0: # strip.set_zone_color(0, head-1, snake_color, 0, True, 0) # strip.set_zone_color(head, tail, background_color, 0, True, 0) # if tail < zone_count - 1: # strip.set_zone_color(tail+1, zone_count-1, snake_color, 0, True, 1) # sleep(delay) except KeyboardInterrupt: # Reset colours to original when the script is stopped strip.set_zone_colors(original_zones, 500, True)