Step 1: Hardware
Connect the NeoPixel Led strip to your Arduino
Step 2: Downloads
- Installed FastLED
- Installed SerialRecord Library
Step 3: Arduino programming
Code on Arduino:
Step 4: Processing Programming
Code on Processing:
import processing.serial.*;
import osteele.processing.SerialRecord.*;
Serial serialPort;
SerialRecord serialRecord;
int W; //width of the tiles
int NUM = 30; //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(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() {
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));
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[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!
}
}
Step 5: Adding Music
- Downloaded Sketch recitation_amplitude_analysis.zip for MACOSX
Code:
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, “beat.aiff”);
sample.loop();
// create the Amplitude analysis object
analysis = new Amplitude(this);
// analyze the playing sound file
analysis.input(sample);
}
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);
}
- Modified the sketch:
- Added different lighting effects
- Experimentation
Leave a Reply