Pages: [1]   Go Down
Author Topic: controling motors with PS3Pad  (Read 897 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey looking for some help writhe code for controlling a H-brige shield with the PS3Pad
i have writhe some basic code but then arduino don't respond to the "second command" that is if i press first TRIANGLE motor runs left but i i press CIRCLE nothing happening and same story i i press CIRCLE motor runs right but i press TRIANGLE nothing happening can some one help
Code:
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
}
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

Pages: [1]   Go Up
Jump to: