Skip to content

Instantly share code, notes, and snippets.

@jerog1
Created March 25, 2014 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerog1/9754519 to your computer and use it in GitHub Desktop.
Save jerog1/9754519 to your computer and use it in GitHub Desktop.
ball-mover Processing
/**
* 2 x Servo Mouse Controller adapted
* Jeremy Nir 2014
* Adapted from original code by Fairlane
*/
import processing.serial.*; // Use the included processing code serial library
//variables
int ANxposition = 15;
int ANyposition = 35;
int theXpaws=90;
int theYpaws=90;
Serial port;
void setup()
{
fill(150);
size(720, 720);
colorMode(RGB, 1.0);
noStroke();
rectMode(CENTER);
frameRate(110);
println(Serial.list()); // List COM-ports is soooo helpful!
//select second com-port from the list
port = new Serial(this, Serial.list()[8], 19200);
}
void draw()
{
// fill(0);
// rect (000,000,1000,1000);
fill(#00aeef);
ellipse (mouseX,mouseY,30,30);
update(mouseX, mouseY); //refresh the x axis
//update(mouseY); //refresh the y axis
}
void update(int x, int y)
{
//find servo
theXpaws= x/6 + 20;
//Calculate servo postion from mouseY
theYpaws= -y/6 + 180;
//write to servo!
port.write("s"+theXpaws);
port.write("w"+theYpaws);
print("x = "+ theXpaws+ ", y = ");
println(theYpaws * 0.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment