Xbox Controller to Control Servo Motor


hi all,

i'm trying control servo xbox controller using arduino.
i got servo going 'sweep' example, trying control xbox controller.
using code.

code: [select]

#include <servo.h>
#include <wire.h> // include library communicating i2c devices
#include <xboxrecv.h> // include xbox receiver library
#ifdef dobogusinclude // satisfy ide, needs see include statement in ino
#include <spi4teensy3.h> // satisfy ide, needs see include statement in ino
#endif // satisfy ide, needs see include statement in ino

usb usb; // define usb host shield
xboxrecv xbox(&usb); // define xbox receiver , usb connection

servo baseservo;
servo servoarmheight;
servo servoarmlength;   
servo clawrotationservo;

int baseservovalue; // define integer servo value
int servoarmheightvalue; // define integer servo value
int servoarmlengthvalue; // define integer servo value
int clawrotationservovalue; // define integer servo value

void setup()
{
  if (usb.init() == -1) // boots usb connection
  {
    while (1); // wait 1ms
  }
 
  serial.begin(115200);
 
  baseservo.attach(11); // define pin
  servoarmheight.attach(10); // define pin
  servoarmlength.attach(9); // define pin
  clawrotationservo.attach(6); // define pin

  baseservo.write(90); // initial angle
  servoarmheight.write(90); // initial angle
  servoarmlength.write(90); // initial angle
  clawrotationservo.write(90); // initial angle
}

void loop()
{
  usb.task(); // gives task usb host shield
  if (xbox.xboxreceiverconnected) // if xbox receiver connected
  {
   for (uint8_t = 0; < 4; i++) // unsigned integer of length 8 bits, variable should = 0, less 4, , should increment +1 @ time
   {
     if (xbox.xbox360connected[i]) // if xbox 360 controller connected, variable defined above
     {
      baseservovalue = map (xbox.getanaloghat(lefthatx, i), 0, 32769, 0, 180); // create integer servo, , map 15 bit value 8 bit value directly
      servoarmheightvalue = map (xbox.getanaloghat(lefthaty, i), 0, -32769, -0, 180); // create integer servo, , map 15 bit value 8 bit value inversely
      servoarmlengthvalue = map (xbox.getanaloghat(righthaty, i), 0, 32769, 0, 180); // create integer servo, , map 15 bit value 8 bit value directly
      clawrotationservovalue = map (xbox.getanaloghat(righthatx, i), 0, -32769, -0, 180); // create integer servo, , map 15 bit value 8 bit value inversely
     }

     baseservo.write(baseservovalue); // ticked servo angle
     servoarmheight.write(servoarmheightvalue); // ticked servo angle
     servoarmlength.write(servoarmlengthvalue); // ticked servo angle
     clawrotationservo.write(clawrotationservovalue); // ticked servo angle
   }
  }
}


however, didn't work , when attached scope servo on pin 11 got trace looked attached image.

i don't have clue , persisted when commented out mapping , final value mapping , told write midpoint of servo.

any ideas?


how arduino communicate usb shield? if uses spi, can't use pins 10, 11, 12, or 13 servos.


Arduino Forum > Using Arduino > Project Guidance > Xbox Controller to Control Servo Motor


arduino

Comments

Popular posts from this blog

sd card Could not find FAT16/FAT32 partition [solved]

DHT11 Time out error using v0.4.1library

Arduino Uno + KTY81/210 temperature sensor