I;m new to processing and would like to use serial data from 2 sensors to play 2 sound files, one per sensor data set.
the code i have is (based on code found here and in Virtual Color Mixer) is as follows (currently only solving for one sensor to work out the bugs)
I am getting the error "it looks like you are mixing active and static modes" Can you give me some advice on where i have confused the modes? will this code let me me add another sensor ?
import ddf.minim.*;
import ddf.minim.signals.*;
import processing.serial.*; // import the Processing serial library
AudioPlayer player;
Minim minim;
Serial myPort; // The serial port
float sensor1Value = 0; // drum value
//float sensor2Value = 0; // piano value
//float sensor3Value = 0; // flute value
float bgcolor; // Background color
float fgcolor; // Fill color
float xpos, ypos; // Starting position of the ball
void setup() {
size(640,480);
minim = new Minim(this);
// load sound file, give the AudioPlayer buffer of 2048
player = minim.loadFile("drum4.mp3", 2048);
// List all the available serial ports
println(Serial.list());
// Open com port of 0 (
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
}
void draw() {
// set the background color with the color values:
background(bgcolor);
fill(fgcolor);
smooth();
ellipse(xpos, ypos, 20, 20);//draw the shape
}
// serialEvent method is run automatically by the Processing applet
void serialEvent(Serial myPort){
// read the serial buffer and get the ASCII string:
String myString = myPort.readStringUntil('\n');
//if bytes other than the linefeed
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString,','));
}
int value=sensors[0];
println("value =" + value);
if (sensor1Value==255&&player != null){player.play();
//if(value==0){player.close();}
// add a linefeed after all the sensor values are printed:
println();
if (sensors.length > 1){
xpos = map(sensors[0], 20,180,0,width);
ypos = map(sensors[1], 20,180,0,height);
fgcolor = sensors[2];
}
// send a byte to ask for more data:
myPort.write("A");
}
}
void stop()
{
// always close Minim audio classes when you are done with them
player.close();
minim.stop();