We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i have a processing code to read serial input from arduino. Everything works fine when i run the code from Processing, however when I exported the application, the Serial commands dont work anymore. I can see my arduino blinking, which means it is sending the data, but nothing on the processing. Thanks
import processing.serial.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Serial s;
Robot robot;
float input;
boolean p = false;
void setup(){
try{
robot = new Robot();
}
catch (AWTException e){
e.printStackTrace();
}
size(500,500);
background(0);
s = new Serial(this, "COM5", 9600);
s.bufferUntil('\n');
frame.removeNotify();
}
void draw(){
if(input == 1){
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
delay(100);
input = 0;
}
else if(input == 2){
robot.keyPress(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_B);
delay(100);
input = 0;
}
}
void serialEvent(Serial s){
String in = s.readStringUntil('\n');
if(in != null){
input = float(in);
println("Raw Input:" + input);
}
}
Answers
And this is the Arduino Code:
Fixed by using the new Processing Alpha 3.0a2
The same as mine, I'll try what you advised. I hope it work.
And yeah, what @Navivanuva said is correct! IT TOTALLY WORKED!!! :D Thank you so much sir!