Creating a sound-reactive WS2812B LED strip using a Raspberry Pi Pico can be a fun project! Here’s a basic guide to get you started:
import array
import math
import audiobusio
import board
import neopixel
# Configuration:
LED_COUNT = 30 # Adjust based on the number of LEDs in your strip
MIC_PIN = board.A0 # Adjust based on the GPIO pin connected to the microphone
BRIGHTNESS = 0.2 # Adjust the LED brightness
pixels = neopixel.NeoPixel(board.GP0, LED_COUNT, auto_write=False)
mic = audiobusio.PDMIn(MIC_PIN, sample_rate=16000, bit_depth=16)
def normalize(values, target_rms):
current_rms = math.sqrt(sum(i ** 2 for i in values) / len(values))
scale = target_rms / current_rms
return array.array(“H”, int(i * scale) for i in values)
while True:
samples = array.array(“H”, mic.record(samples))
normalized_samples = normalize(samples, 32767)
for i in range(LED_COUNT):
intensity = normalized_samples[i] / 65535.0
pixels[i] = (int(intensity * 255), 0, 0)
pixels.show()
Remember, this is a basic example, and you can customize the script based on your preferences. Adjustments can be made to the LED arrangement, color patterns, and sensitivity to create a more dynamic sound-reactive LED display. Have fun experimenting!
Â
It will take just few seconds to claim 7% Discount, After Submitting check Email for Coupon code.
Leave a Reply
You must be logged in to post a comment.