using your code i have this so far...
#include <PS2X_lib.h> //for v1.6
#include <Servo.h>
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always restart your Arduino after you conect the controller
int error = 0;
byte type = 0;
byte vibrate = 0;
int val;
// Servo's
Servo steering;// create servo object to control a servo
Servo drive; // a maximum of eight servo objects can be created
Servo gear;
void setup(){
Serial.begin(57600);
//Set pin num
steering.attach(30); // attaches the servo on pin 30 to the servo object
drive.attach(34); //attaches the servo on pin 32 to the servo object
// #### SET THESE PINS ####
error = ps2x.config_gamepad(38,42,40,44, true, true); //setup pins and settings: GamePad(clock(38), command(42), attention(40), data(44), Pressures?, Rumble?) check for error
if(error == 0){
Serial.println("Found Controller, configured successful");
}
else if(error == 1)
Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
else if(error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
//Serial.print(ps2x.Analog(1), HEX);
type = ps2x.readType();
switch(type) {
case 0:
Serial.println("Unknown Controller type");
break;
case 1:
Serial.println("DualShock Controller Found");
break;
case 2:
Serial.println("GuitarHero Controller Found");
break;
}
// error = 0; // Skips error checking for controller
// type = 1;
} // END OF SET UP
void loop(){
if(error == 1) //skip loop if no controller found
return;
else { //DualShock Controller
ps2x.read_gamepad(); // Needs to be called at least once a second
{ // Steering
val = (ps2x.Analog(PSS_LX)); // val = Left stick X (0-255)
val = map(val, 0, 225, 45, 135); // Convert Left X(0-255) to Servo angle(135-45)
steering.write(val); // write angle to servo
delay(15); // wait for servo to get there ( .0015 of a second)
}
{ //drive
val = (ps2x.Analog(PSS_RY)); // val = Left stick X (0-255)
val = map(val, 0, 225, 135, 45); // Convert Left X(0-255) to Servo angle(135-45)
drive.write(val); // write angle to servo
delay(15); // wait for servo to get there ( .0015 of a second)
}
int hi = 0;
boolean test = false;
if(ps2x.Button(PSB_L2))
{
test = true;
if(hi == 1)
{
gear.write(50);
hi = 0;
test = false;
}
if(hi == 0 && test)
{
gear.write(25);
hi++;
}
}
int hi2 = 0;
boolean test2 = false;
if(ps2x.Button(PSB_R2))
{
test2 = true;
if(hi2 == 1)
{
myServo.write(0);
hi2 = 0;
test2 = false;
}
if(hi2 == 0 && test2)
{
myServo.write(25);
hi2++;
}
}
delay(50);
}
} // END OF LOOP