Recitation 7: Neopixel Music Visualization

Task 1: I connected the Neopixel and the Arduino and uploaded the Blink software from fast LED to test to see if these components were working. 

Task 2: I installed SerialRecord and uploaded the sample code. I was able to light up specific lights by sending values into the Serial Monitor. I also installed Serial Record on Processing and was able to get the sample code to work, where I would the mouseX value would correlate to a value for the LED on the NeoPixel.

Task 3: At first I had difficulty trying to combine the codes on Processing. I needed to discern the necessary elements from those that were unnecessary. I was able to map the volume with the number of LED lights. But had difficulty at first because I forgot the part that included the information about the ports. I replaced the beat.aif with an audio of a song I like (“It Just Is”- Eaj and Seori mp3 converted to wav).

Following the third step, I was able to use millis to change the amount of red light using if, else if, and else statements, such as the one provided.

I built off this ability to map the volume with the number of the LED, I started to play with the colors. I started by trying to have the red color align with the volume as well. I originally wanted to try and find a way to reset the light so that the light would turn off after the volume had changed to a smaller value. But as of right now, I found this to be a bit too complex. I also looked at potentially using the FFT but while trying to understand I realized that I did not need to use it. In the end, I returned to millis and mapped the millis, the total being around the same length as the audio, with the amount of blue and green. In addition to the color of the LED, I used the same variables for the color of the circles. 

I pasted my final code for processing below, I left the sample code for Arduino as it was given.

import processing.sound.*;
import processing.serial.*;
import osteele.processing.SerialRecord.*;

Serial serialPort;
SerialRecord serialRecord;
SoundFile sample;
Amplitude analysis;



void setup() {
  size(640, 480);

  // load and play a sound file in a loop
  sample = new SoundFile(this, "It-Just-Is.wav");
  sample.loop();

  // create the Amplitude analysis object
  analysis = new Amplitude(this);
  // analyze the playing sound file
  analysis.input(sample);


  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, "COM7", 9600);
  serialRecord = new SerialRecord(this, serialPort, 4);
  serialRecord.logToCanvas(false);
  rectMode(CENTER);
}

void draw() {
  println(analysis.analyze());
  background(0, 0, 0);
  noStroke();

  // 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)

  int n = floor(map(diameter, 0, width, 0, 59));
  int r = floor(map(volume, 0, 1, 0, 255));

  int c=0;
  long t = millis();

  if (t < 180000) {
    c = floor(map(t, 0, 180000, 0, 255));
  } else if (t==180000) {
    c = 255;
  }

  fill(r, c, c);
  circle(width/2, height/2, diameter);

  println(n);
  serialRecord.values[0] = n;     // which pixel we change (0-59)
  serialRecord.values[1] = r;  // how much red (0-255)
  serialRecord.values[2] = c;  // how much green (0-255)
  serialRecord.values[3] = c;  // how much blue (0-255)
  serialRecord.send();            // send it!
}

Leave a Reply

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