Disco Frame - That Beats According to the Volume of the Music

by cabarca2 in Circuits > Arduino

408 Views, 2 Favorites, 0 Comments

Disco Frame - That Beats According to the Volume of the Music

IMG_1607_jpg.JPG
IMG_1608.JPG
Disco frame - lights and music

 


Learn how to create a frame of LEDs that change colors according to the volume/rhythm of the music. This cool masterpiece is the perfect complement whenever you want to pregame, have dinner with friends or just listen to music at home on in your room.



Supplies

IMG_1545_jpg.JPG
IMG_1479.JPG
IMG_1291_jpg.JPG
IMG_1476.JPG


Circuit Diagram and Code

Screen Shot 2022-12-13 at 22.34.04.png
IMG_1476.JPG

For the digital circuit, I used a potentiometer to simulate the behavior of a microphone, but It was replaced by a microphone when I built the physical one.

The code:

*/
#include <Adafruit_NeoPixel.h>
// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 6


// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 200


// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)


int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)


void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}


void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);

if(outputValue >=230)
{
theaterChase(strip.Color(outputValue, outputValue, outputValue), 100); // White, half brightness
}
else if (outputValue >=215)
{
theaterChase(strip.Color(outputValue,120,0), 50); // yellow, half brightness
}
else if (outputValue >=200)
{
theaterChase(strip.Color(outputValue,outputValue+130,outputValue-60), 50); // Pink, half brightness
}
else if (outputValue >=190)
{
theaterChase(strip.Color(outputValue, 255, 0), 50); // White, half brightness
}


else if (outputValue >=170)
{
theaterChase(strip.Color(outputValue,150 , 200), 50); // Blue, half brightness
}
else if (outputValue >=160)
{
theaterChase(strip.Color(30,80,outputValue+60), 50); // blue, half brightness
}
else if (outputValue >=145)
{
theaterChase(strip.Color(outputValue-40,outputValue+130,outputValue-60), 50); // pink, half brightness
}
else if (outputValue >=130)
{
theaterChase(strip.Color(outputValue,50,0), 50); // Orange, half brightness
}
else if (outputValue >=115)
{
theaterChase(strip.Color(200,0,0), 50); // Red, half brightness
}
else if (outputValue >=80)
{
theaterChase(strip.Color(140,200,30), 50); // Green, half brightness
}
else {


AudioReact();

}
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);


// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}


void AudioReact() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
for(int i=0; i<50; i++) { // For each pixel in strip...
strip.setPixelColor(i, strip.Color(255, outputValue, outputValue*2)); // Set pixel's color (in RAM)
}
strip.show(); // Update strip to match
delay(50); // Pause for a moment


for(int i=50; i<100; i++) { // For each pixel in strip...
strip.setPixelColor(i, strip.Color(255, outputValue, outputValue)); // Set pixel's color (in RAM)
}
for(int i=100; i<150; i++) { // For each pixel in strip...
strip.setPixelColor(i, strip.Color(outputValue, outputValue, 255)); // Set pixel's color (in RAM)
}
for(int i=150; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, strip.Color(outputValue+55, 255, outputValue+30)); // Set pixel's color (in RAM)
}
strip.show(); // Update strip to match
delay(1000); // Pause for a moment
}


// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
// between frames.
void theaterChase(uint32_t color, int wait) {
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}


Frame Assembling

IMG_1288_jpg.JPG
IMG_1476.JPG
IMG_1547_jpg.JPG
IMG_1546_jpg.JPG
IMG_1482.JPG
IMG_1497.JPG
IMG_1485.JPG
IMG_1803.JPG

Once the circuit and the code is ready, it is time to assemble all the parts!

First of all, choose your text design and play with the LED before you stick it.

Then, it is important to affix the neon lights to a Bristol board or similar material. I highly recommend to use epoxy glue and duck tape as the clamp backing.

After that, make a hole in the Bristol board and the cardboard that come with the frame and run the breadboard wires through the hole.

Finally, place the circuit in the back of the frame and plug it into a USB power adapter.

Play Music and Enjoy

IMG_1606_jpg.JPG
IMG_1605.JPG
IMG_1607_jpg.JPG

Pick a song, play and enjoy it.

TIP:

You can also customize the sign, light colors and effects for a specific song and give it to someone special :)