Thanks for your quick answer!
I have changed the program as you said but now, I still receive my 5 datas but only one v0 (the first) is mapped!
This value, v0 trig a sound but sometimes it doesn’t.
Actually I send position of a motor which go from 0 to 2774.
Then I map it in Processing from 0 to 36 (as 0 to 360°).
Each time my motor make a round, I want Processing trig a sound.
Maybe, sometimes v0 is not between (v0>=36|| v0<=0) ???
So what to do?
I have always my problem disabling my serial but I’ll see it later.
/**
* This sketch demonstrates how to use the <code>loadSample</code> method of <code>Minim</code>.
* The <code>loadSample</code> method allows you to specify the sample you want to load
* with a <code>String</code> and optionally specify what you want the buffer size of the
* returned <code>AudioSample</code> to be. Minim is able to load wav files, au files, aif
* files, snd files, and mp3 files. When you call <code>loadSample</code>, if you just
* specify the filename it will try to load the sample from the data folder of your sketch.
* However, you can also specify an absolute path (such as "C:\foo\bar\thing.wav") and the
* file will be loaded from that location (keep in mind that won't work from an applet).
* You can also specify a URL (such as "http://www.mysite.com/mp3/song.mp3") but keep in mind
* that if you run the sketch as an applet you may run in to security restrictions
* if the applet is not on the same domain as the file you want to load. You can get around
* the restriction by signing all of the jars in the applet.
* <p>
* An <code>AudioSample</code> is a special kind of file playback that allows
* you to repeatedly <i>trigger</i> an audio file. It does this by keeping the
* entire file in an internal buffer and then keeping a list of trigger points.
* <code>AudioSample</code> supports up to 20 overlapping triggers, which
* should be plenty for short sounds. It is not advised that you use this class
* for long sounds (like entire songs, for example) because the entire file is
* kept in memory.
* <p>
* Use 'k' and 's' to trigger a kick drum sample and a snare sample, respectively.
* You will see their waveforms drawn when they are played back.
* <p>
* For more information about Minim and additional features,
* visit http://code.compartmental.net/minim/
*/
import processing.serial.*; // import data from Arduino
Serial myPort; // The serial port
int v0 = 0;
int v1 = 0;
int v2 = 0;
int v3 = 0;
int v4 = 0;
int x;
import ddf.minim.*;
Minim minim;
AudioSample kick;
AudioSample snare;
void setup()
{
background (255);
size(1000,800);
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[4], 115200);
// Read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil('\n');
minim = new Minim(this);
// load BD.wav from the data folder
kick = minim.loadSample( "BD.mp3", // filename
512 // buffer size
);
// An AudioSample will spawn its own audio processing Thread,
// and since audio processing works by generating one buffer
// of samples at a time, we can specify how big we want that
// buffer to be in the call to loadSample. k
// above, we requested a buffer size of 512 because
// this will make the triggering of the samples sound more responsive.
// on some systems, this might be too small and the audio
// will sound corrupted, in that case, you can just increase
// the buffer size.
// if a file doesn't exist, loadSample will return null
if ( kick == null ) println("Didn't get kick!");
// load SD.wav from the data folder
snare = minim.loadSample("SD.wav", 512);
if ( snare == null ) println("Didn't get snare!");
}
void draw()
{
background(0);
stroke(255);
// use the mix buffer to draw the waveforms.
for (int i = 0; i < kick.bufferSize() - 1; i++)
{
float x1 = map(i, 0, kick.bufferSize(), 0, width);
float x2 = map(i+1, 0, kick.bufferSize(), 0, width);
line(x1, 50 - kick.mix.get(i)*50, x2, 50 - kick.mix.get(i+1)*50);
line(x1, 150 - snare.mix.get(i)*50, x2, 150 - snare.mix.get(i+1)*50);
}
// Draw circles
fill(25);
ellipse(x, v0+250, 5, 5);
fill(50);
ellipse(x, v1+350, 5, 5);
fill(75);
ellipse(x, v2+450, 5, 5);
fill(100);
ellipse(x, v3+550, 5, 5);
fill (125);
ellipse(x, v4+650, 5, 5);
// Update x position
x++;
// Refresh screen
if (x > width) {
background(255);
x = 0;
}
}
void keyPressed()
{
if ( key == 's' ) snare.trigger();
if ( key == 'k' ) kick.trigger();
if ( key == 'j' ) kick.trigger();
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
println(myString);
// split the string at the commas
// and convert the sections into integers:
int values[] = int(split(myString, ','));
if (values.length > 0) {
// CARFUL when problem disabling serial port, stop, unplugge, play again
v0 = (int)map(values[0], 0, 2774, 0, 36);
v1 = (int)map(values[1], 0, 2774, 0, 36);
v2 = (int)map(values[2], 0, 2774, 0, 36);
v3 = (int)map(values[3], 0, 2774, 0, 36);
v4 = (int)map(values[4], 0, 2774, 0, 36);
println (v0); println (v1); println (v2); println (v3);
if (v0>=36|| v0<=0) snare.trigger();
// if (int (v1)==0) snare.trigger();
}
}
I send this from Arduino
for(uint8_t i = 0; i < NBMOTEURS; i++) {
Serial.print(position[i]);
Serial.print(", ");
} //Serial.println("");
// */
Serial.println();
}