Loading...
Logo
Processing Forum
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:

Copy code
  1. import java.awt.AWTException;
  2. import processing.serial.*;
  3. import java.awt.Robot;
  4.  Serial myPort;
  5. Robot robot;
  6. boolean act=false;
  7.  
  8. void setup() {
  9.   size(400, 400);
  10.    myPort = new Serial(this, "COM11", 115200);
  11.   try { 
  12.     robot = new Robot();
  13.   } 
  14.   catch (AWTException e) {
  15.     e.printStackTrace();
  16.   }
  17.   robot.mouseMove(250,250);
  18. }
  19. void serialEvent(Serial myPort) {
  20. {
  21.     String serial = myPort.readString();
  22.     if (serial=="act")
  23.   {
  24.    act=true;
  25.   }
  26.   else if (serial=="desact");
  27.   {
  28.   act=false;
  29.   }
  30.     myPort.clear();
  31.   
  32. }}
  33. void draw()
  34. {
  35. if (act==true)
  36. {
  37. robot.mouseMove(0,0);
  38. }
  39. else if (act==false)
  40. {
  41. //dont do enything
  42. }}
Any suggestions?
And sorry if my english is bad, im spanhis!