daily pastebin goal
14%
SHARE
TWEET

Pololu Micro Maestro darylrobotproject.wordpress.com

a guest Dec 18th, 2012 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #define TXPIN 6
  3. #define RXPIN 7
  4.  
  5. #define HONRIZONTAL 0
  6. #define VERTICAL 1
  7.  
  8. SoftwareSerial maestro(RXPIN, TXPIN);
  9. void setup()
  10. {
  11.   // Define the appropriate input/output pins
  12.   pinMode(RXPIN, INPUT);
  13.   pinMode(TXPIN, OUTPUT);
  14.   maestro.begin(115200);
  15.   delay(1000);  
  16. }
  17. void loop()
  18. {
  19.   settarget(VERTICAL, 79);
  20.   settarget(HONRIZONTAL, 90);
  21.   delay(1000);
  22.   move();
  23.   delay(1000);
  24. }
  25.  
  26. void move() {
  27.  
  28.   settarget(HONRIZONTAL, 60);
  29.   delay(500);
  30.  
  31.   int i=60;
  32.     while(i<=120)
  33.     {
  34.         settarget(HONRIZONTAL, i);
  35.         delay(100);
  36.         i++;
  37.     }
  38.    
  39.   delay(500);
  40.   settarget(HONRIZONTAL, 90);
  41.   goHome();
  42. }
  43.  
  44. void settarget(unsigned char servo, unsigned int target)
  45. {
  46.   target = map(target, 0, 100, 608*4, 2224*4);
  47.   maestro.write(0xAA); //start byte
  48.   maestro.write(0x0C) ; //device id
  49.   maestro.write(0x04); //command number
  50.   maestro.write(servo); //servo number
  51.   maestro.write(target & 0x7F);
  52.   maestro.write((target >> 7) & 0x7F);
  53. }
  54.  
  55. void goHome()
  56. {
  57.   maestro.write(0xAA); //start byte
  58.   maestro.write(0x0C) ; //device id
  59.   maestro.write(0x22); //go home command number
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top