from adafruit_led_animation.animation.pulse import Pulse from adafruit_led_animation.color import RED # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 # Update to match the number of NeoPixels you have connected pixel_num = 32 # Update to matchpin connected to button that connect logic high when pushed button_pin = board.D3 pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) button = DigitalInOut(button_pin) button.direction = Direction.INPUT button.pull = Pull.UP # Create the animation and freeze it afterwards pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED) pulse_animation.freeze() while True: pulse_animation.animate() # Pressing the button resumes (or in this case starts) the animation permanently if not button.value: pulse_animation.resume()
BGM = "/lucio/bgmheal.mp3" else: BGM = "/lucio/bgmspeed.mp3" sample0 = audiomp3.MP3Decoder(open(BGM, "rb")) FX = "/lucio/shoot.mp3" sample1 = audiomp3.MP3Decoder(open(FX, "rb")) speaker.play(mixer) mixer.voice[0].play(sample0, loop=True) mixer.voice[0].level = 0.3 * VOLUME_MULT mixer.voice[1].level = 0.7 * VOLUME_MULT while True: if mode_state: # heal mode on startup vu_strip_animations_mode0.animate() pulse_rings_m0.animate() pulse_jewel_m0.animate() else: # speed mode on startup vu_strip_animations_mode1.animate() pulse_rings_m1.animate() pulse_jewel_m1.animate() # Change modes if mode_switch.value: if mode_state == 0: # state has changed, toggle it BGM = "/lucio/bgmheal.mp3" sample0.file = open(BGM, "rb") mixer.voice[0].play(sample0, loop=True) vu_strip_animations_mode0.animate() pulse_rings_m0.animate() pulse_jewel_m0.animate()
elif mode >= 1: # If not OFF mode... x, y, z = accel.acceleration # Read accelerometer accel_total = x * x + z * z # (Y axis isn't needed, due to the orientation that the Prop-Maker # Wing is mounted. Also, square root isn't needed, since we're # comparing thresholds...use squared values instead.) if accel_total > HIT_THRESHOLD: # Large acceleration = HIT TRIGGER_TIME = time.monotonic() # Save initial time of hit play_wav(random.choice(hit_sounds)) # Start playing 'hit' sound solid.animate() mode = 3 # HIT mode elif mode == 1 and accel_total > SWING_THRESHOLD: # Mild = SWING TRIGGER_TIME = time.monotonic() # Save initial time of swing play_wav(random.choice( swing_sounds)) # Randomly choose from available swing sounds while audio.playing: pass # wait till we're done mode = 2 # we'll go back to idle mode elif mode == 1: pulse.animate() elif mode > 1: # If in SWING or HIT mode... if audio.playing: # And sound currently playing... blend = time.monotonic() - TRIGGER_TIME # Time since triggered if mode == 2: # If SWING, blend = abs(0.5 - blend) * 2.0 # ramp up, down else: # No sound now, but still SWING or HIT modes play_wav('idle', loop=True) # Resume idle sound mode = 1 # Return to idle mode