Recitation 7: Neopixel Music Visualization
In task #1, I followed the directions to connect the NeoPixels to the Arduino board and download the libraries on Arduino and Processing. After this, I opened the FastLED/Blink example to make sure the NeoPixel was working, which it was; the first LED was blinking.
In task #2, I downloaded the codes provided. This code allowed me to change the position and color of the LED based on my serial monitor input.
In task #3, I downloaded a song from YouTube and converted it to MP3. Then, I replaced the old file on the code with my new MP3. The pink circle on the screen moves with the volume of the music.
In the beginning, I had trouble getting the music to play because I didn’t check if the file worked before inserting it to the code. After I discovered this problem, I used a different MP3 converter.
In this part, I changed the code to add different actions to the LED strip. This action allows different parts of the LED to light up with the volume. I also adjusted the colors.
CODE:
import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; int W; //width of the tiles int NUM = 60; //amount of pixels int[] r = new int[NUM]; //red of each tile int[] g = new int[NUM]; //red of each tile int[] b = new int[NUM]; //red of each tile import processing.sound.*; SoundFile sample; Amplitude analysis; void setup() { size(640, 480); // load and play a sound file in a loop sample = new SoundFile(this, "youtube.mp3"); sample.loop(); // create the Amplitude analysis object analysis = new Amplitude(this); // analyze the playing sound file analysis.input(sample); size(600, 200); W = width/NUM; // You can use this syntax and change COM3 for your serial port // printArray(Serial.list()); // serialPort = new Serial(this, "COM3", 9600); // in MacOS it looks like "/dev/cu.usbmodem1101" //or you can try to use this instead: String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 4); serialRecord.logToCanvas(false); rectMode(CENTER); } void draw() { println(analysis.analyze()); background(125, 255, 125); noStroke(); fill(255, 0, 150); // analyze the audio for its volume level float volume = analysis.analyze(); // volume is a number between 0.0 and 1.0 // map the volume value to a useful scale float diameter = map(volume, 0, 1, 0, width); // draw a circle based on the microphone amplitude (volume) circle(width/2, height/2, diameter); background(0); for (int i=0; i<NUM; i ++) { fill(r[i], g[i], b[i]); rect(i * W + W/2, height/2, 10, 10); } //if (mousePressed == true) { //int n = floor(constrain(mouseX/W , 0, NUM-1)); int n =floor(map(volume,0,1,0,59)); r[n] = floor(map(volume,1,0,0,255)); g[n] = floor(map(volume,0,1,0,255)); b[n] = floor(map(volume,0,1,0,255)); serialRecord.values[0] = n; // which pixel we change (0-59) serialRecord.values[1] = r[n]; // how much red (0-255) serialRecord.values[2] = g[n]; // how much green (0-255) serialRecord.values[3] = b[n]; // how much blue (0-255) serialRecord.send(); // send it! //} }