Errors in Serial Comunication with Arduino
in
Integration and Hardware
•
2 months ago
Hellow!
I want to move de mouse, using the Robot Library, depending of the string that the Arduino send via serial comunication. The problem is that the Processing program dont recive well the string, it miss a part. Here is the code that i am working:
- import java.awt.AWTException;
- import processing.serial.*;
- import java.awt.Robot;
- Serial myPort;
- Robot robot;
- boolean act=false;
- void setup() {
- size(400, 400);
- myPort = new Serial(this, "COM11", 115200);
- try {
- robot = new Robot();
- }
- catch (AWTException e) {
- e.printStackTrace();
- }
- robot.mouseMove(250,250);
- }
- void serialEvent(Serial myPort) {
- {
- String serial = myPort.readString();
- if (serial=="act")
- {
- act=true;
- }
- else if (serial=="desact");
- {
- act=false;
- }
- myPort.clear();
- }}
- void draw()
- {
- if (act==true)
- {
- robot.mouseMove(0,0);
- }
- else if (act==false)
- {
- //dont do enything
- }}
Any suggestions?
And sorry if my english is bad, im spanhis!
1