For dealing explicitly with the complexity of sound input, it is effective to visualize the data in processing. Here are the steps I made for letting Arduino talk to Processing. refer to ->> Processing Serial Library ->> Arduino Play Ground / Arduino meets Processing / Potentiometer
[step1]
ASM06_001AP-potValues
It is a potentiometer value that has to be visualized here in its processing code. When the pot knob is turned, the incoming value gradually changes. (>> a variable resistor)
>> Arduino Code >> Processing Code
import processing.serial.*;
Serial myPort;
PFont myFont;
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
int value = 0;
int valNorm = 0;
String buf="";
int xpos = 0;
void setup() {
// if(inString==null)inString="100";
size(460,100);
myFont = loadFont("CourierNewPSMT-18.vlw");
println(Serial.list());
myPort = new Serial(this, "COM2", 14400);
myPort.bufferUntil(lf);
frameRate(20);
}
void draw() {
while(myPort.available() > 0){
value = myPort.read();
println("value "+value);
serialEvent(value);
}
background(255);
uploading();
fill(0);
textFont(myFont, 18);
text("pot receives; " + valNorm,10,35); //"received: " + inString
}
void serialEvent(int serial){ // if serial event is not a line break
if(serial!=10) {
buf += char(serial); // add event to buffer
println("buf"+buf);
}
else {
valNorm = int(buf); // if serial is line break set valNorm to buff and clear it
println("valNorm---"+valNorm);
buf="";
}
// convert valNorm to xpos
// xpos = constrain ( ( /width ) ,0, width-12);
// if(output) println("xpos: "+xpos);
}
void uploading(){
noStroke();
fill(255, 0, 0);
rect((valNorm*0.44)+1023/width, 60,4,40 );
}