We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm currently stuck with a bit of code and i am relatively new to processing. I'm currently sending across a data from an arduino with a Bluetooth device to my laptop, this works fine but and the correct value is being sent and received. The issue is that the character is displayed for a too small amount of time before it disappear, is there a simple way to stop this? also the text box displays NULL for the first letter can this also be edited?
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val;
String sa3;
void setup() {
size(400, 400);
textSize(20);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(51);
if (myPort.available() > 0) {
val = myPort.readString();
if (val == null) {
println(""); // This line is printed
}
else {
if(val !="") {
sa3 = sa3 + val;
text(sa3, 10, 100);
}
}
}
println(sa3);
}
Thanks :)
Answers
edit post, highlight code, press ctrl-o to format the code.
background() clears the screen. maybe move it inside the condition.
it doesnt seem to make a difference
https://forum.Processing.org/two/discussion/14534/myport-available-always-0#Item_1
https://forum.Processing.org/two/discussion/16618/processing-with-arduino-void-serialevent#Item_5
Change line 5 to
String sa3 = "";
. Remove background call. Right now, you don't need it.Alternatively, use this code:
That works brilliantly thanks
Best of luck.