In my living room at my house I installed audio reactive LED lights to visualize music coming from my speakers.
The original code written by Scott Lawson only visualized the audio input and if there wasn't audio input the LED's would scroll and change colors. My living room did not have an overhead light so I wanted the lights to be used as the lights for the room as well as an audio visualizer. The idea was to edit the code to when there was no audio input, the lights would stay a consistent color and act as the lights for the room.
This is an overview of the changes I made to the original repository.
- In config.py there is a variable called
MIN_VOLUME_THRESHOLD = 1e-7
.- I checked the average volume by printing the volume of the microphone input stream. I found that with no input the volume was around 0.3. There was a small amount of volume because of the bluetooth receiver I use and my speakers.
- I changed
MIN_VOLUME_THRESHOLD = 0.3
so that when there is no music playing the pixels would be a consistent color.
- The main script visualization.py uses ([led.py]led.py) to set the color of each pixel.
- led.py uses a library rpi_ws821x to communicate with the LED's.
- rpi_ws281x has a function called
setPixelColor(n, red, green, blue)
to set the color of a pixel on the led strip.- n = Position of LED
- r, g, b = RGB value of the pixel
- I added a function called
NoAudio()
in led.py that iterates through each pixel of the strip and sets the color to the desired color. - Then call
strip.show()
to display the pixels.
- The main script visualization.py visualizes the audio input (
microphone_update()
). If the volume was below the threshold it would scroll through colors.- I removed the scrolling effect and called
strip.NoAudio()
to set the desired color when there is no input to the pixels.
- I removed the scrolling effect and called
This is the first time I have made changes to an existing repository to fit my needs.
I learned how to SSH into a Raspberry Pi to make changes to the code already on the device because it is in an area that can't be used.
I learned how to fork an exisiting repository and post my chnages on GitHub.
I displayed that I can read someone's existing code and how it works to be able to make the chnages I wanted to make.
The repository includes everything needed to build an LED strip music visualizer (excluding hardware):
- Python visualization code, which includes code for:
- Recording audio with a microphone (microphone.py)
- Digital signal processing (dsp.py)
- Constructing 1D visualizations (visualization.py)
- Sending pixel information to the ESP8266 over WiFi (led.py)
- Configuration and settings (config.py)
- Arduino firmware for the ESP8266 (ws2812_controller_esp8266.ino)
This project was developed by Scott Lawson and is released under the MIT License.