@bking
one way to do it:
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;
int[] values;
String out;
//char end = "z";
void setup() {
size (500, 800);
// frameRate(30);
// colorMode(RGB, 255, 255, 255, 100);
values = new int[3];
arduinoport = new Serial(this, "COM0", 9600); //replace 0 with the port the arduino is connected to (see arduino IDE)
/*
if on linux or macos, it's better to list all ports using: "String[] ports = arduinoport.list();"
then look for the index of the port you want to connect to, and instead of "COMX" in the new Serial above,
set ports[index]. 9600 is the baudrate, make sure this is the same in the arduino Serial monitor
example:
String[] ports = Serial.list();
printArray(ports);
arduinoport = new Serial(this,ports[0],9600);
*/
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];
values[0] = int(w1*100000);
values[1] = int(w2*100000);
values[2] = int (phiV*100000);
int valueW1 = int(w1*100000);
int valueW2 = int(w2*100000);
int valuephiV = int(phiV*100000);
//both possible
//String out = nf(valueW1,4) + nf(valueW2,4) + nf(valuephiV,4);
String out = nf(values[0], 3)+"*"+nf(values[1], 4) +"*"+ nf(values[2], 4)+"*";
String out1 = nf(valueW1, 3) + "*" + nf(valueW2, 4) + "*" + nf(valuephiV, 4) + "*";
//println(out);
//println(out1);
arduinoport.write(out);
//or: arduinoport.write(out1);
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;
}
as you’re using 1D arrays,it’s not useful to use 3 separate arrays. either use 1 2D array or 3 separate variables.
also, in order to see when one value stops and the other begins (necessary for reading on the Arduino), split them with a different character, in this case i used " * " , but it can be anything as long as it isn’t a number.
then on the Arduino use Serial.readStringUntil(" * "); to read until this character to get the value in front of it.
use a for-loop to get all 3 values.