Hi,
I’m trying to send 3 variable w1, w2 and phiV which are 3 parameter changing with the mouse tracking.
I was trying to place those variable in 3 arrays and add it in a string but it didn’t work.
I think there is one or several steps i have missed somewhere.
Can I send a float array or just an int array?
I put my program
import processing.serial.*;
Serial arduinoport;
float w1, w2;
float w12twist = 10.0;
//int x=1;
int Um=100;
int Vm=100;
float phiU=0;
float phiV=HALF_PI/2;
float X1t, X2t,X3t,X4t,X5t;
float y=100.0;
String out;
//char end = "z";
void setup() {
size (500, 800);
// frameRate(30);
// colorMode(RGB, 255, 255, 255, 100);
println("use mouse X for freq, mouse Y for VM phase and mouseWheel for w1/w2");
}
void draw() {
int[] valueW1 = new int[1];
int[] valueW2 = new int[1];
int[] valuephiV = new int[1];
for (int i = 0; i < valueW1.length; i++) {
valueW1[i] = int(w1*100000);
valueW2[i] = int(w2*100000);
valuephiV[i] = int (phiV*100000);
}
printArray(valueW1);
printArray(valueW2);
printArray(valuephiV);
//String out = nf(valueW1,4) + nf(valueW2,4) + nf(valuephiV,4);
String out = nf(valueW1,3) + nf(valueW2,4) + nf(valuephiV,4);
println(out);
arduinoport.write(out);
background(150,150,150);
//For example
for (int x=0;x<500;x++){
w1 = mouseX/500.0/PI;
w2 = 1.2*w1;
//w2 = 12.0/w12twist*w1;
//INTERPRETATION:
//Si w12twist= 1 => 12 amplitude max pour une periode "quand le motif se repète" et X1t dephasés de 1/2 de periode de X2t
//Si w12twist= 0.7 => bcp amplitude max avant que la periode repete et toujours meme dephasage
//Si w12twist= 9.69 => bcp amplitude max avant que la periode repete et toujours meme dephasage
phiV=PI*mouseY/500.0;
//phiV=phiV+PI/4000; //vitesse lente et constante de "propagation?"
//phiV=PI*mouseY/500.0;
// decale X1t et X2t de la meme periode
// !!! changer les constantes phiv et/ou phiU n'a pas d'incidence sur "le decalage" X1t et X2t
float y=0.01;
X1t= Um/2*cos(w1*x+phiU) - Vm/2*cos(w2*x+phiV);
X2t= Um/2*cos(w1*x+phiU) + Vm/2*cos(w2*x+phiV);
X3t= Um *exp (-y*x/2)* cos(w1*x+phiV);
X4t= 50*cos(w1*x+phiV);
//!!! nonce n'es pas la somme X5t= Um *exp (-y*x/2)* cos(w1*x+phiV)+ 50*cos(w1*x+phiV);
//X5t= Um *exp (-y*x/2)* cos(*w1*x)+ Um;
X5t = Um*sin(x*0.1)*sin(w1*x+phiV);
//Draw something...
noStroke();
fill(0,w1 ,50);
ellipse (x,X1t+150, 5, 5);
fill(0,50, w1);
ellipse (x,X2t+350, 5, 5);
fill(w1,50, 0);
ellipse (x,X3t+550, 5, 5);
ellipse (x,X4t+650,5,5);
ellipse (x,X5t+750,5,5);
//println(W1, w1, w2, w12twist, phiV);
}
}
void mouseWheel(MouseEvent event) {
w12twist += event.getCount()/10.0;
}
After I will have to read it in Arduino, and I don’t know the way to do it, but I 'll see step by step.
Thanks