Go Down

Topic: controling motors with PS3Pad (Read 970 times) previous topic - next topic

THX_RoG

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: [Select]

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
}

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy