# Are we connected via Bluetooth now? if ble.connected: # Once we're connected, we're not advertising any more. advertising = False # Have we started to receive a packet? if uart.in_waiting: packet = Packet.from_stream(uart) if isinstance(packet, ColorPacket): # Set all the pixels to one color and stay there. pixels.fill(packet.color) pixels.show() MODE = 2 elif isinstance(packet, ButtonPacket): if packet.pressed: if packet.button == ButtonPacket.BUTTON_1: animations.activate(1) elif packet.button == ButtonPacket.BUTTON_2: MODE = 1 animations.activate(2) elif packet.button == ButtonPacket.BUTTON_3: MODE = 1 animations.activate(3) elif packet.button == ButtonPacket.BUTTON_4: MODE = 4 elif packet.button == ButtonPacket.UP: pixels.brightness = pixels.brightness + 0.1 pixels.show() if pixels.brightness > 1: pixels.brightness = 1 elif packet.button == ButtonPacket.DOWN:
#Packet is arriving packet = Packet.from_stream(uart_service) if isinstance(packet, ButtonPacket) and packet.pressed: if packet.button == ButtonPacket.BUTTON_1: # Animation colors change to a random new value after every animation sequence random_color_mode = True elif packet.button == ButtonPacket.BUTTON_2: # Animation colors stay the same unless manually changed random_color_mode = False elif packet.button == ButtonPacket.BUTTON_3: # Stay on the same animation animations._advance_interval = None elif packet.button == ButtonPacket.BUTTON_4: # Auto-advance animations animations._advance_interval = seconds_per_animation*1000 elif packet.button == ButtonPacket.LEFT: # Go to first animation in the sequence animations.activate(0) elif packet.button == ButtonPacket.RIGHT: # Go to the next animation in the sequence animations.next() elif isinstance(packet, ColorPacket): animations.color = packet.color pulse.color = packet.color # temporarily change to pulse display to show off the new color current_display = pulse else: if not ble.advertising: ble.start_advertising(advertisement)
# Advertise when not connected elif MODE >= 1: # If not OFF MODE... ble.start_advertising(advertisement) while not ble.connected: MODE, on_at, off_at = handleClap(MODE, on_at, off_at) if MODE == 2: pass elif MODE == 1: animations.animate() elif MODE == 3: now = time.time() if (now - start_at) > duration: print("event finished") MODE = 1 animations.activate(0) animations.animate() elif MODE == 4: animations.freeze() # Now we're connected while ble.connected: MODE, on_at, off_at = handleClap(MODE, on_at, off_at) if uart_service.in_waiting: packet = Packet.from_stream(uart_service) # Color Picker Functionality if isinstance(packet, ColorPacket): MODE = 2 # Set all the pixels to one color and stay there. pixels.fill(packet.color) pixels.show()