tail_length=6, bounce=False) comet1 = Comet(pixels, speed=0.05, color=(255, 255, 0), tail_length=6, bounce=True) rainbow = Rainbow(pixels, speed=0.1, period=2, step=10) animations = AnimationSequence(comet, comet1, rainbow, advance_interval=6) comet.add_cycle_complete_receiver(switch_colors) comet.notify_cycles = 2 ble = BLERadio() uart_service = UARTService() advertisement = ProvideServicesAdvertisement(uart_service) while True: #advertise when not connected ble.start_advertising(advertisement) while not ble.connected: animations.animate() ble.stop_advertising() while ble.connected: animations.animate() if uart_service.in_waiting: packet = Packet.from_stream(uart_service) if isinstance(packet, ColorPacket): animations.color = packet.color animations.reset()
was_connected = False while not was_connected or ble.connected: if not blanked: # If LED-off signal is not being sent... animations.animate() # Run the animations. if ble.connected: # If BLE is connected... was_connected = True if uart.in_waiting: # Check to see if any data is available. try: packet = Packet.from_stream( uart) # Create the packet object. except ValueError: continue if isinstance(packet, ColorPacket): # If the packet is color packet... if mode == 0: # And mode is 0... animations.color = packet.color # Update the animation to the color. print("Color:", packet.color) animation_color = packet.color # Keep track of the current color... elif mode == 1: # Because if mode is 1... animations.color = animation_color # Freeze the animation color. print("Color:", animation_color) elif isinstance( packet, ButtonPacket): # If the packet is a button packet... if packet.pressed: # If the buttons in the app are pressed... if packet.button == ButtonPacket.LEFT: # If left arrow is pressed... print("A pressed: animation mode changed.") animations.next() # Change to the next animation. elif packet.button == ButtonPacket.RIGHT: # If right arrow is pressed... mode += 1 # Increase the mode by 1. if mode == 1: # If mode is 1, print the following: