Pages: [1] 2   Go Down
Author Topic: MAking mouse move using Pots  (Read 911 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have written the following code in processing
import processing.serial.*;
Serial myPort;
int valX,valY;

void setup()
{ background(0);
  size(1024,1024);
  myPort=new Serial(this,Serial.list()[0],9600);
}
void draw()
{ void serialEvent(Serial myPort)
    {
      String myString=myPort.readStringUntil(124);
      if(myString!=null)
   {
     myString=trim(myString);
     int inputs[]=int(split(myString,','));
     if(inputs.length==2)
   { valX=inputs[0];
    valY=inputs[1];
   }
 
   }
    }
    mouseX=valX;
    mouseY=valY;
    fill(225);
    ellipse(mouseX,mouseY,2,2);
   if(mousePressed)
  {background(0);
  }
}

Its giving me an error while declaring the serialEvent as "unexpected token:void".
processing.app.SketchException: unexpected token: void
   at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:326)
   at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197)
   at processing.mode.java.JavaBuild.build(JavaBuild.java:156)
   at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
   at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
   at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
   at java.lang.Thread.run(Thread.java:662)

wats the error?I am still not able to figure out...Please help!!!
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 25
Posts: 1131
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting ... and where does the Arduino come into this? (drives the servo, yes)

May I suggest the Processing forum ( http://forum.processing.org )? Remember that Processing is based on Java, the Arduino is based on C++ - similar yet different smiley

Lastly, the probable error is that you are nesting function defenitions.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply...
Im using pots on arduino as analog inputs..
the code is
Code:
int potX=A0;
int potY=A1;
int valX,valY;
void setup()
{ Serial.begin(9600);
}
void loop()
{
  valX=analogRead(potX);
  valY=analogRead(potY);
  Serial.print(valX,DEC);
  Serial.print(",");
  Serial.print(valY,DEC);
  Serial.print("|");
}
Logged

Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


mouseX and mouseY are used to read the mouses position. you cannot assign a value to them (or maybe you can, I dont know, but they will never move the curser).

take a look at this link: http://download.oracle.com/javase/1.3/docs/api/java/awt/Robot.html

I have done something similar in the past using robot class.

if you cant make it work, feel free to ask more questions, I can digg up my old code somewhere and take a look at how I did it.

p.
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 236
Posts: 24266
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
"unexpected token:void".
As MSquare pointed out, it is most likely this:
Code:
void draw()
{ void serialEvent(Serial myPort)
nested function definition that the compiler is complaining about.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6886
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


  myPort=new Serial(this,Serial.list()[0],9600);


How sure are you that arduino is the first serial port on that list? I'm sure mine is the last on the list. You really should have asked on Processing forum for this code.
Logged


Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

but the processing forum is horrible to navigate and has an awkward layout and I personally dont like it at all ... and it is an arduino project, so let the guy ask his questions.

and especially (I didnt look at the code beyond the mouseX/mouseY issue) if the actual problem he has is in the setup of the serial communication

edit: with me it always is the first serial port
« Last Edit: July 25, 2011, 11:57:08 am by fkeel » Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6886
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial port number may depend on operating system. On my windows machines they are always last.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As some of the friends suggested it "was" the problem of nested functions ..i have corrected the same..
The serial communication is no problem as i had done many serial projects on arduino before..but i sent or received only one value...but this time i was experimenting with two values...
I have configured on one serial port on my laptop that is com7 so it always comes first in serial.list() at an index[0]...
Friends the problem i am now facing is that the mousex works but mouseY doesnt respond...
And lastly.. as some suggested that i should try the processing forum..i did it and i did it in the past too..but i get no replies and on this forum i get reply within a few minutes..

Thanks..
CAN U  TELL ME HOW to MAKE mouseY  work??
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6886
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So what did you use in the robot class, this one?

mouseMove(int x, int y)
          Moves mouse pointer to given screen coordinates.

Can you repost your codes?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@liudr
the new code is this..but still the mouseY is not working and in the output window the value of mouseY is always 0..I didnt use the robotclass...
Code:
import processing.serial.*;
Serial myPort;
int valX,valY;

void setup()
{ background(0);
  size(1024,1024);
  myPort=new Serial(this,Serial.list()[0],9600);
}
void draw()
{ serialEvent(myPort);
    mouseX=valX;
    mouseY=valY;
    fill(225);
    ellipse(mouseX,mouseY,20,20);
   if(mousePressed)
  {background(0);
  }
}
void serialEvent(Serial myPort)
    {
      String myString=myPort.readStringUntil(124);
      if(myString!=null)
   {
     myString=trim(myString);
     int inputs[]=int(split(myString,','));
     if(inputs.length==2)
   { valX=inputs[0];
    valY=inputs[1];
   }
 
   }
    }
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 25
Posts: 1131
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if mouseX works, but mouseY does not ... presumes that the communication is working.

So, have you confirmed that potY is actually sending other values than 0 ? Or the string actually has the format you expect 2142,3453|

Try putting a print(myString) in. (or is it myString.print - my Processing skills are rusty)
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6886
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As Msquare said your poty may not work. Can we see your arduino code and picture of your setup?
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void draw()
{ serialEvent(myPort);
    mouseX=valX;
    mouseY=valY;
    fill(225);
    ellipse(mouseX,mouseY,20,20);
   if(mousePressed)
  {background(0);
  }
}
The serialEvent() function is called whenever there is serial data for you to read. You should NEVER call serialEvent() directly.
Logged

Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have already explained to you. mouseX and mouseY are special variables reserved for reading the coordinates of your curser.

You are not interested in reading where your curser is. As far as I can tell, you are trying to move an ellipse within a processing sketch. Do not use mouseX and mouseY as variables for doing this, as it is bound to lead to problems.
« Last Edit: July 26, 2011, 02:52:17 pm by fkeel » Logged


Pages: [1] 2   Go Up
Jump to: