Created
March 25, 2014 03:03
-
-
Save jerog1/9754519 to your computer and use it in GitHub Desktop.
ball-mover Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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