interpolate between the two colors and return a gamma-corrected in-between color as a packed 24-bit RGB integer. No bounds clamping is performed on blend value, be nice.""" inv = 1.0 - blend # Weighting of second color return gammify([color1[x] * blend + color2[x] * inv for x in range(3)]) # HARDWARE SETUP ----------------------- # Manually declare I2C (not board.I2C() directly) to access 1 MHz speed... i2c = I2C(board.SCL, board.SDA, frequency=1000000) # Initialize the IS31 LED driver, buffered for smoother animation glasses = LED_Glasses(i2c, allocate=adafruit_is31fl3741.MUST_BUFFER) glasses.show() # Clear any residue on startup glasses.global_current = 20 # Just middlin' bright, please # INITIALIZE TABLES & OTHER GLOBALS ---- # This table is for mapping 3x3 averaged bitmap values (0-9) to # RGB colors. Avoids a lot of shift-and-or on every pixel. colormap = [] for n in range(10): colormap.append(gammify([n / 9 * eye_color[x] for x in range(3)])) # Pre-compute the Y position of 1/2 of the LEDs in a ring, relative # to the 3X bitmap resolution, so ring & matrix animation can be aligned. y_pos = [] for n in range(13): angle = n / 24 * math.pi * 2
# SPDX-FileCopyrightText: 2021 Rose Hooper # SPDX-License-Identifier: MIT import board from adafruit_led_animation.animation.sparkle import Sparkle from adafruit_led_animation.color import PURPLE from adafruit_led_animation.sequence import AnimationSequence from adafruit_is31fl3741.adafruit_ledglasses import MUST_BUFFER, LED_Glasses from adafruit_is31fl3741.led_glasses_animation import LED_Glasses_Animation glasses = LED_Glasses(board.I2C(), allocate=MUST_BUFFER) glasses.set_led_scaling(255) glasses.global_current = 0xFE glasses.enable = True pixels = LED_Glasses_Animation(glasses) anim2 = Sparkle(pixels, 0.05, PURPLE) group = AnimationSequence(anim2, advance_interval=5, auto_reset=True, auto_clear=True) while True: group.animate()
fft_size = 256 # Sample size for Fourier transform, MUST be power of two spectrum_size = fft_size // 2 # Output spectrum is 1/2 of FFT result # Bottom of spectrum tends to be noisy, while top often exceeds musical # range and is just harmonics, so clip both ends off: low_bin = 10 # Lowest bin of spectrum that contributes to graph high_bin = 75 # Highest bin " # HARDWARE SETUP --------- # Manually declare I2C (not board.I2C() directly) to access 1 MHz speed... i2c = I2C(board.SCL, board.SDA, frequency=1000000) # Initialize the IS31 LED driver, buffered for smoother animation glasses = LED_Glasses(i2c, allocate=adafruit_is31fl3741.MUST_BUFFER) glasses.show() # Clear any residue on startup glasses.global_current = 5 # Not too bright please # Initialize mic and allocate recording buffer (default rate is 16 MHz) mic = PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, bit_depth=16) rec_buf = array("H", [0] * fft_size) # 16-bit audio samples # FFT/SPECTRUM SETUP ----- # To keep the display lively, tables are precomputed where each column of # the matrix (of which there are few) is the sum value and weighting of # several bins from the FFT spectrum output (of which there are many). # The tables also help visually linearize the output so octaves are evenly # spaced, as on a piano keyboard, whereas the source spectrum data is # spaced by frequency in Hz. column_table = []