I'm doing this project where I'm using an Arduino Board to read the heartbeat pulses, so I want to send from the Arduino to Processing only one number (the BPM of the person); so that I can use that information into my Processing code to manipulate some visual image that I have created in Processing. My problem at the moment is that that information is in String(), so I can't use it as a variable - Int() or float() - and I'm having difficulties in making this conversion, from String to Int().
This is my code at the moment:
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val;
void setup () {
size(600,600);
noStroke();
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
}
float t=0;
void draw() {
background(0);
fill(255);
if ( myPort.available() > 0) { // If data is available,
val = myPort.readStringUntil('\n'); // read it and store it in val
println(val);
}
translate(width/2, height/2);
beginShape ();
//add some vertices...
for (float theta =0; theta <= 2*PI; theta += 0.01){
float rad = r(theta,
2, //a
2, //b
6, //m
1, //n1
cos(t)*0.9+0.7 , //n2
sin(t)*0.9+0.7 //n3
);
float x = rad * cos(theta)*100;
float y = rad * sin(theta)*100;
vertex (x,y);
}
endShape(CLOSE);
t+=0.04;
}
float r(float theta, float a, float b, float m, float n1, float n2, float n3 ) {
return pow(pow(abs(cos(m* theta/4.0) /a), n2) + pow(abs(sin(m* theta/4.0) /b), n3), -1.0/n1);
}
I have tried this to convert the String() to Int() but it doesn´t seem to work:
Serial myPort;
String val;
int valInt;
void draw ();
if ( myPort.available() > 0) {
val = myPort.readStringUntil('\n');
int valInt = Integer.parseInt(val);
println(valInt);
}