Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Servocontrol (derived from processing Mouse 1D example.)
- *
- * Updated 24 November 2007
- */
- // Use the included processing code serial library
- import processing.serial.*;
- int spos=90;
- int spos2=90;
- Serial port; // The serial port
- void setup()
- {
- size(720, 720);
- colorMode(RGB, 1.0);
- noStroke();
- rectMode(CENTER);
- frameRate(100);
- println(Serial.list()); // List COM-ports
- //select second com-port from the list
- port = new Serial(this, Serial.list()[0], 57600);
- println("Connected to:"+port);
- }
- void draw()
- {
- background(0.0);
- update(mouseX, mouseY);
- }
- void update(int x, int y)
- {
- //Calculate servo postion from mouse x and y axis
- spos= x/4;
- spos2= y/4;
- //Output the servo position ( from 0 to 180)
- port.write(spos+"s"); //x axis
- port.write(spos2+"w"); //y axis
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement