Recitation 7: Neopixel Music Visualization

I finished task1 by connecting the Neopixel like this to check whether the Neopixel is working well.

I then used the code provided to light the Neopixel like this. I decided to make the sixth one lighting up and having the red color so I entered “2,255,0,0”.

I also used the provided codes to experience this interactive mini project. I found it interesting because it adopts a more natural way to circulate messages between the processing and arduino. In this kind of interaction, the interaction is also arranged properly so that the colorful little rectangles on screen are associated with every part of Neopixel in order. 

I then downloaded the provided code and changed the music into my own ones. I found that the file did not work well because I transform the music file in a weird way so that it could not be read by processing properly and thus errors happen. After I asked Learning Assistant, I changed to downloading music files from music apps and it worked.

I then used the same music from the last step and I added the code below in the very beginning to include the functions that I needed.

Serial serialPort;
SerialRecord serialRecord;

I then added the code below in the setup() to set the basics for transporting messages from processing to arduino.
String serialPortName = SerialUtils.findArduinoPort();
serialPort = new Serial(this, serialPortName, 9600);
serialRecord = new SerialRecord(this, serialPort, 4);
serialRecord.logToCanvas(false);

I then added the code below in the draw() to use the data from analyzing of music and send it to the arduino.

int v = floor(constrain(volume, 0, NUM-1));
r[v] = floor(random(255));
g[v] = floor(random(255));
b[v] = floor(random(255));
int n = int(map(volume, 0,1,0,NUM-1));
serialRecord.values[0] = n;
serialRecord.values[1] = r[v];
serialRecord.values[2] = g[v];
serialRecord.values[3] = b[v];
serialRecord.send();

I used all these functions to achieve the result that the order of Neopixel which is lit up is determined by volume of the music and the color of it changes with the volume. At first, I found that only the first Neopixel was lit up and the color changes in a very weird way like below.

I then asked help from professor Rudi and he told me that it is because the volume of the music is too high that the first value I used in the map() function is too small so it will only map the value to around 0 to 1. I then changed the code like the one above. Finally, the entire process works like the video shows below.

Leave a Reply

Your email address will not be published. Required fields are marked *