Hey guys i have some problem with my code after uploading it to arduino PS3Pad get connected nothing happens my servo dont react
hers the code
#include <Servo.h>
#include <Spi.h>
#include <PS3BT.h>
Servo servoOne; // create servo object for first Servo
Servo servoTwo; // create servo object for second Servo
USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd, 0x00, 0x02, 0x5B, 0x00, 0x29, 0x50);
int PositionOne, PositionTwo; //storage for servo positions
char servomode; // mode for servo control 0 = joystick 1 = accelerometer
boolean printTemperature;
boolean printAngle;
void setup(){
Serial.begin(115200);
Usb.Init();
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 USB Library Started"));
servoOne.attach(2); // attaches the first servo on pin 0 to the servo object
servoTwo.attach(3); // attaches the first servo on pin 1 to the servo object
}
void loop(){
Usb.Task(); // perform the regular USB routines
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
if(PS3.buttonPressed){ // right and left buttons change mode joystick/Accelerometer
if(PS3.getButton(LEFT)) {
servomode = 0;
PS3.setAllOff();
PS3.setLedOn(LED2);
Serial.println(F("SERVOMODE 0"));
}
if(PS3.getButton(RIGHT)) {
servomode = 1;
PS3.setAllOff();
PS3.setLedOn(LED3);
Serial.println(F("SERVOMODE 1"));
}
}
if(servomode){ // Accelerometer mode
PositionOne = constrain(PS3.getAnalogHat(LeftHatX), 400, 600); // constrain to +/- 1g
PositionOne = map(PositionOne, 400, 600, 0, 179); // scale it to use it with the servo
PositionTwo = constrain(PS3.getAnalogHat(LeftHatY), 400, 600); // constrain to +/- 1g
PositionTwo = map(PositionTwo, 400, 600, 0, 179); // scale it to use it with the servo
}
else{ // Joystick mode
PositionOne = map(PS3.getButton(TRIANGLE), 0, 255, 0, 179); // scale it to use it with the servo
PositionTwo = map(PS3.getButton(CIRCLE), 0, 255, 0, 179); // scale it to use it with the servo
}
}
servoOne.write(PositionOne); //sets the first servo position according to the scaled value
servoTwo.write(PositionTwo); // sets the first servo position according to the scaled value
delay(15); // waits for the servo low time
}
servo is SG-5010 Tower Pro