Problem hooking Xbox controller to Arduino and changing part of the program

Hi how do you change everything pertaining to the flex sensors and L3G4200D substituting it for Xbox controls without using a Wifi shield anything would help thank you.

//Arduino 1.0+ only

#include <Wire.h>
#include <Servo.h>

#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24

int L3G4200D_Address = 105;

int x;
int y;
int z;

Servo Pinky;
Servo Ring;
Servo Index;
Servo Pointer;
Servo Thumb;

int val;
int val1;
int val2;
int val3;
int val4;

int smoothedRotation;

float filterVal; // this determines smoothness - .0001 is max 1 is off (no smoothing)
float smoothedVal; // this holds the last loop value just use a unique variable for every different sensor that needs smoothing
float smoothedVal1;
float smoothedVal2;
float smoothedVal3;
float smoothedVal4;

Servo WRotation;
Servo WLeftRight;
Servo WUpDown;

void setup(){

Wire.begin();
Serial.begin(9600);

Serial.println("starting up L3G4200D");
setupL3G4200D(2000); // Configure L3G4200 - 250, 500 or 2000 deg/sec

delay(1500); //wait for the sensor to be ready
WRotation.attach(12);
WLeftRight.attach(13);
WUpDown.attach(11);
Pinky.attach(7);
Ring.attach(6);
Index.attach(5);
Pointer.attach(4);
Thumb.attach(3);
}

void loop(){
getGyroValues(); // This will update x, y, and z with new values

//Serial.print("X:");
//Serial.print(x);

//Serial.print(" Y:");
//Serial.print(y);

delay(100); //Just here to slow down the serial to make it more readable

x = map(x, -1023, 1023, 0, 179);
//Serial.print(" X:");

smoothedRotation = smoothrotation(x, filterVal, smoothedRotation);
if(x<60)
{
x=90;
//do
//{
WRotation.write(x);
delay(50);
// }while(WRotation.read()>60);
// Serial.println(x);
}
if (x>100)
{
x=170;
// do
//{
WRotation.write(x);
delay(50);
//}while(WRotation.read()<170);
// Serial.println(x);
}else
{
WRotation.write(x);
}

z = map(z, -1023, 1023, 0, 179);
//Serial.print("Z:");
if(z<50)
{
z=40;
}
if (z>110)
{
z=100;
}
//Serial.print(z);
WLeftRight.write(z);

y = map(y, -1023, 1023, 40, 100);
// Serial.print(" Y:");
// if(y<20)
//{
// y=20;
//}
//if (y>110)
//{
// y=120;
//}
// Serial.print(180 - y);
WUpDown.write(180 - y);

val = analogRead(0); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179);
val1 = analogRead(1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 179);
val2 = analogRead(2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 0, 179);
val3 = analogRead(3); // reads the value of the potentiometer (value between 0 and 1023)
val3 = map(val3, 0, 1023, 0, 179);
val4 = analogRead(4); // reads the value of the potentiometer (value between 0 and 1023)
val4 = map(val4, 0, 1023, 0, 179);

filterVal = 0.05;

smoothedVal = smooth(val, filterVal, smoothedVal); // second parameter determines smoothness - 0 is off, .9999 is max smooth
smoothedVal1 = smooth(val1, filterVal, smoothedVal1); // second parameter determines smoothness - 0 is off, .9999 is max smooth
smoothedVal2 = smooth(val2, filterVal, smoothedVal2); // second parameter determines smoothness - 0 is off, .9999 is max smooth
smoothedVal3 = smooth(val3, filterVal, smoothedVal3); // second parameter determines smoothness - 0 is off, .9999 is max smooth
smoothedVal4 = smooth(val4, filterVal, smoothedVal4); // second parameter determines smoothness - 0 is off, .9999 is max smooth

if (smoothedVal > 120)
{
Pinky.write(60);
// Serial.print("smoothed val: ");
// Serial.print(smoothedVal);
// Serial.print(" ");
// Serial.print(val);
// Serial.print(" ");
// Serial.println("60");
}
else if(smoothedVal<60)
{
Pinky.write(180);
// Serial.print("smoothed val: ");
// Serial.print(smoothedVal);
// Serial.print(" ");
// Serial.print(val);
// Serial.print(" ");
// Serial.println("180");
}
delay(15);

if (smoothedVal1 > 120)
{
Ring.write(60);
}
else if(smoothedVal1<60)
{
Ring.write(180);
}
delay(15);

if (smoothedVal2 > 120)
{
Index.write(60);
}
else if(smoothedVal2<60)
{
Index.write(180);
}
delay(15);

if (smoothedVal3 > 120)
{
Pointer.write(60);
}
else if(smoothedVal3<60)
{
Pointer.write(180);
}
delay(15);

if (smoothedVal4 > 120)
{
Thumb.write(60);
}
else if(smoothedVal4<60)
{
Thumb.write(180);
}
delay(15);

}

void getGyroValues(){

byte xMSB = readRegister(L3G4200D_Address, 0x29);
byte xLSB = readRegister(L3G4200D_Address, 0x28);
x = ((xMSB << 8) | xLSB);

byte yMSB = readRegister(L3G4200D_Address, 0x2B);
byte yLSB = readRegister(L3G4200D_Address, 0x2A);
y = ((yMSB << 8) | yLSB);

byte zMSB = readRegister(L3G4200D_Address, 0x2D);
byte zLSB = readRegister(L3G4200D_Address, 0x2C);
z = ((zMSB << 8) | zLSB);
}

int setupL3G4200D(int scale){
//From Jim Lindblom of Sparkfun's code

// Enable x, y, z and turn off power down:
writeRegister(L3G4200D_Address, CTRL_REG1, 0b00001111);
// If you'd like to adjust/use the HPF, you can edit the line below to configure CTRL_REG2:
//writeRegister(L3G4200D_Address, CTRL_REG2, 0b00000000);
// Configure CTRL_REG3 to generate data ready interrupt on INT2
// No interrupts used on INT1, if you'd like to configure INT1
// or INT2 otherwise, consult the datasheet:
//writeRegister(L3G4200D_Address, CTRL_REG3, 0b00001000);

// CTRL_REG4 controls the full-scale range, among other things:

if(scale == 250){
writeRegister(L3G4200D_Address, CTRL_REG4, 0b00000000);
}else if(scale == 500){
writeRegister(L3G4200D_Address, CTRL_REG4, 0b00010000);
}else{
writeRegister(L3G4200D_Address, CTRL_REG4, 0b00110000);
}

// CTRL_REG5 controls high-pass filtering of outputs, use it
// if you'd like:
writeRegister(L3G4200D_Address, CTRL_REG5, 0b00000000);

}

void writeRegister(int deviceAddress, byte address, byte val) {
Wire.beginTransmission(deviceAddress); // start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); // end transmission
}

Below is how i'm going to set it up but without the flex sensors and this is not the entire file the whole thing is in the attachment

sketch_dec09b.ino (8.92 KB)

Here's the photo attached to the top post.

Next time you post a photo you can insert the uploaded image by following these instructions.

Please read the "How to use this forum - please read" thread. Item #7 explains how to post code. If you use code tags you could likely fit the entire program a post.

People are more likely to look at your code if they don't have to download it first. (The same goes for photos.)

Have you successfully interfaced with the L3G4200D?

It looks like you want to use the gyro to control some servos. What sort of movement do you want to capture and what do you want the servos to do?

A gyro can sense how fast something rotates. I does not provide orientation information.

If you're looking for a sensor to determine the orientation of your hand (other other item), Adafruit sell the BNO055 9DOF sensor. It is very good at sensing orientation. It's presently my favorite IMU type sensor.

Thank you for replying and for the tips.
I would like to take out the gyro controlling the motors instead a want to use a Xbox 360 controller.
I'm trying to make a robotic arm.
The first 5 motors on the left control the fingers.
The ones on the left control wrist movement and arm movement.
Hope you reply and thank you.

leedo1:
I would like to take out the gyro controlling the motors instead a want to use a Xbox 360 controller.

Sorry, I had it backwards.

I've never used a XBox 360 controller myself but (IIRC) you need a USB host shield to use one with an Arduino.

Apparently the XBox 360 controller is a nice one but it's not very microcontroller friendly. There are lots of other controllers which would be a lot easier to use with an Arduino.

Here's my example of using a Wii Nunchuck with an Arduino (the program also works with wireless Nunchucks).

I think PlayStation 2 controller and GameCube controllers are also relatively easy to use with an Arduino.

If you want to use the XBox 360 controller, you'll likely need additional hardware in order to interface it with an Arduino (and I'm sure there are plenty of examples of how to do this).