Recitation 7: Neopixel Music Visualization

This is after running the first neopixel program that I ran. When the mouse is pressed it draws a line of cubes with randomized colors, this changes every time the mouse is pressed.

This was a more complicated program whereby the code reacts to sound of the input song and as a result a circle varies in size depending on the amplitude of the sound.

The last task was to merge the previous code and the LED strip to make it react to the music. the result is shown in the video’s .As you can see the the light reacts to the music but it is very slow. this is a challenge I had I and I think it can be fixed by changing the Millis function to a smaller number. My code is below.

import processing.sound.*;
import processing.serial.*;
import osteele.processing.SerialRecord.*;
SoundFile sample;
Amplitude analysis;
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

void setup() {
  size(640, 480);
  W = width/NUM;
  // load and play a sound file in a loop
  sample = new SoundFile(this, "Drake.wav");
  sample.loop();

  // create the Amplitude analysis object
  analysis = new Amplitude(this);
  // analyze the playing sound file
  analysis.input(sample);
  printArray(Serial.list());
  serialPort = new Serial(this, "COM9", 9600);
  serialRecord = new SerialRecord(this, serialPort, 4);
  serialRecord.logToCanvas(false);
}

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

  if (frameCount%30 ==0) {
    int n = floor(map(volume, 0, 1, 0,NUM-1));

    r[n] = floor(random(255));
    g[n] = floor(random(255));
    b[n] = floor(random(255));

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

Leave a Reply

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