Stepper Motor control using PS3 controller

Hi,
I have been following this tutorial on how to connect a PS3 controller to my arduino uno via a USB host shield. The tutorial takes you only as far as printing the PS3 buttons pressed on the serial monitor (which it now does) but now I want to put it to good use. I want to control a car which operates via two stepper motors but I'm unsure how to do it. My code from the tutorial is below and I just want to make it so when either the joystick is moved, the stepper motors move accordingly.

#include <PS3BT.h>
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
PS3BT PS3(&Btd); // This will just create the instance
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

boolean printTemperature;
boolean printAngle;

void setup() {
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
}
void loop() {
Usb.Task();

if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY));
Serial.print(F("\tRightHatX: "));
Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
Serial.print(PS3.getAnalogHat(RightHatY));
}

//Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3.getAnalogButton(L2_ANALOG));
Serial.print(F("\tR2: "));
Serial.print(PS3.getAnalogButton(R2_ANALOG));
}
if(PS3.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
PS3.disconnect();
}
else {
if(PS3.getButtonClick(TRIANGLE))
Serial.print(F("\r\nTraingle"));
if(PS3.getButtonClick(CIRCLE))
Serial.print(F("\r\nCircle"));
if(PS3.getButtonClick(CROSS))
Serial.print(F("\r\nCross"));
if(PS3.getButtonClick(SQUARE))
Serial.print(F("\r\nSquare"));

if(PS3.getButtonClick(UP)) {
Serial.print(F("\r\nUp"));
if(PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED4);
}
}
if(PS3.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight"));
if(PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED1);
}
}
if(PS3.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown"));
if(PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED2);
}
}
if(PS3.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft"));
if(PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED3);
}
}
}
}

I am using an easy driver module ( Easy Driver Examples ) to operate the steppers. The joy stick has analog values (0-255) and I want to make use of the AccelStepper library to increase the speed of the steppers accordingly. Can anyone help? I am very new to all of this. Cheers

Links to tutorial and USB Host Shield Library are below.
Tutorial: How to Connect a PS3 controller to an Arduino with a USB host shield and Bluetooth dongle (Part 1) - YouTube
USB Host Library: GitHub - felis/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.

I've also attached the relevant files that are used for my code.

PS3BT.cpp (27.8 KB)

PS3BT.h (6.29 KB)

want to control a car which operates via two stepper motors but I'm unsure how to do it. ... I just want to make it so when either the joystick is moved, the stepper motors move accordingly.

Well, the second statement explains the first. What does "move accordingly" mean in terms of number of steps that the stepper motor needs to step and the speed that the motor needs to step? It doesn't mean anything. When you can define the relationship between what the motor needs to do and the value obtained from the joystick, you'll be in a much better position to translate that into code.

Although I am new at this myself. I am currently working on a project of similar needs. I know this post is older but you never know if someone else might have found the answer and could stumble upon this thread later with the key.

I am building a 6 axis robot arm that I want to control with a ps3 controller, because who needs a crawl phase right?

If anyone knows of a code of this nature, i would surely appreciate it.

I am building a 6 axis robot arm that I want to control with a ps3 controller

Which of the 6 axes are you controlling at any given time? What events on the controller are supposed to affect that motor that drives that axis? How do you switch which axis is being controller?

Until you define EXACTLY what you want to do, your chances of success are no higher than OPs.

@R48811, are you using stepper motors in your project?

You may be interested in stepper motor basics

...R

Oh yeah, maybe I should give more details.... my bad.
So, im not positive on what buttons i want to control what joint. However I do have a list of motor functions and controler keystrokes i want to use. I just have to draw the line between the two lists.
they are as follows.

Motor locations /actions.
*Side to side track slide
*arm base 360 rotation
*bottom joint lift/reach
*elbow joint reach
*wrist, back 360 rotation
*wrist 180 bend joint
*wrist, front 360 rotation
*pinch claw

Joystick gestures, as they would be for each motor.
*left joystick L/R
*left joystick UP/DOWN
*right joystick L/R
*right joystick UP DOWN
*L1 R1
*L2 R2
*Dpad L/R
*Dpad UP/DOWN
*Square /Circle
*Triangle /X

So as im sure you noticed there are more gestures than motors. That is because I still haven't made the layout of what motor gos best with what gesture. I will obviously be leaving 2 uncoded or use the buttons for a nerf gun or something.

What i was originally looking for when i found this post was a generic template code for the ps3 controller that I could just fill in the blanks or something...

Regardless, i mainly have been looking around for code that is similar and I can adapt. So far no luck.

So as im sure you noticed there are more gestures than motors.

That may be the case, but 4 of the "gestures" give you a range of values, while 6 give you 0 or 1. I can't see how 0 or 1 will be of much use in making a servo move through it's range of motions.

On the other hand, making each of the 6 0 or 1 "gestures" correspond to the 6 servos, and one of the range of value "gestures" control the motion of the servo WOULD make sense.