It was so excited to perform my favorite songs in a visual way.
First, following the instruction, I began to make LEDs work. It was so cool to order the LEDs light by importing their numbers. Also, the third step in task 2 was also wonderful: as the color of the LEDs can change randomly while I slide my mouse, which was so interesting. Here are the videos of these two steps:
After done these steps, I started to combine the music with both processing codes and LEDs. In this way, the lights and the circle in the screen will move with the music. Here are video and codes:
import processing.sound.*;
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 tileSoundFile sample;
Amplitude analysis;void setup() {
size(640, 480);
W = width/NUM;// load and play a sound file in a loop
sample = new SoundFile(this, “Lauv-Paris In The Rain.mp3”);
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, 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);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));
r[n] = floor(random(255));
g[n] = floor(random(255));
b[n] = floor(random(255));serialRecord.values[0] = floor(map(volume,0,1,0,60)); // which pixel we change (0-59)
serialRecord.values[1] = r[floor(map(volume,0,1,0,255))]; // how much red (0-255)
serialRecord.values[2] = g[floor(map(volume,0,1,0,255))]; // how much green (0-255)
serialRecord.values[3] = b[floor(map(volume,0,1,0,255))]; // how much blue (0-255)
serialRecord.send(); // send it!
}}