Advertisement
Guest User

Twin servo control (processing)

a guest
Jun 15th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. /**
  2.  * Servocontrol (derived from processing Mouse 1D example.)
  3.  *
  4.  * Updated 24 November 2007
  5.  */
  6.  
  7.  
  8. // Use the included processing code serial library
  9. import processing.serial.*;        
  10.  
  11.  
  12. int spos=90;
  13. int spos2=90;
  14.  
  15. Serial port;                         // The serial port
  16.  
  17.  
  18.  
  19. void setup()
  20. {
  21.   size(720, 720);
  22.   colorMode(RGB, 1.0);
  23.   noStroke();
  24.   rectMode(CENTER);
  25.   frameRate(100);
  26.  
  27.   println(Serial.list()); // List COM-ports
  28.  
  29.   //select second com-port from the list
  30.   port = new Serial(this, Serial.list()[0], 57600);
  31.   println("Connected to:"+port);
  32. }
  33.  
  34. void draw()
  35. {
  36.   background(0.0);
  37.   update(mouseX, mouseY);
  38.  
  39. }
  40.  
  41. void update(int x, int y)
  42. {
  43.   //Calculate servo postion from mouse x and y axis
  44.   spos= x/4;
  45.   spos2= y/4;
  46.  
  47.   //Output the servo position ( from 0 to 180)
  48.   port.write(spos+"s"); //x axis
  49.   port.write(spos2+"w"); //y axis
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement