user10450: I'm having trouble with controlling my car with the PS3 joystick, and there hasn't been any example codes out there. I'm using;

PS3USB library from USB_Host_shield_2.0 library
Freetronics H Bridge shield http://www.freetronics.com.au/collections/shields/products/hbridge-dual-channel-h-bridge-motor-driver-shield#.VXMqXUJJmgM

This is my code; 
include <PS3USB.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
//PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printAngle;
uint8_t state = 0;

int motora1 = 4;
int motora2 = 7;
int motoraspeed = 6;
int motorb1 = 3;
int motorb2 = 2;
int motorbspeed = 5;


void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nPS3 USB Library Started"));
  pinMode(motora1, OUTPUT);
  pinMode(motora2, OUTPUT);
  pinMode(motoraspeed, OUTPUT); 
  pinMode(motorb1, OUTPUT);
  pinMode(motorb2, OUTPUT);
  pinMode(motorbspeed, OUTPUT);  
  delay(5000); 
}

void loop() {
  Usb.Task();

  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    //go forward
     if (PS3.getAnalogHat(LeftHatY) == 0) {
       Serial.print(F("\r\nLeftHatY: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
         digitalWrite(motora1, HIGH);
          digitalWrite(motora2, LOW);
          digitalWrite(motoraspeed, 255);
        digitalWrite(motorb1, HIGH);
        digitalWrite(motorb2, LOW);
        digitalWrite(motorbspeed, 255);  
}

//go backward
if (PS3.getAnalogHat(LeftHatY) == 255) {
       Serial.print(F("\r\nLeftHatY: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
           digitalWrite(motora1, LOW);
  digitalWrite(motora2, HIGH);
  digitalWrite(motoraspeed, 255);
  digitalWrite(motorb1, LOW);
  digitalWrite(motorb2, HIGH);
  digitalWrite(motorbspeed, 255);  
}

//turn left
if (PS3.getAnalogHat(RightHatX) == 0) {
       Serial.print(F("\r\RightHatX: "));
      Serial.print(PS3.getAnalogHat(RightHatX));
           digitalWrite(motora1, HIGH);
  digitalWrite(motora2, LOW);
  digitalWrite(motoraspeed, 200);
  digitalWrite(motorb1, LOW);
  digitalWrite(motorb2, HIGH);
  digitalWrite(motorbspeed, 200);   
}

   //turn right
   if (PS3.getAnalogHat(RightHatX) == 255) {
       Serial.print(F("\r\RightHatX: "));
      Serial.print(PS3.getAnalogHat(RightHatX));
          digitalWrite(motora1, LOW);
  digitalWrite(motora2, HIGH);
  digitalWrite(motoraspeed, 200);
  digitalWrite(motorb1, HIGH);
  digitalWrite(motorb2, LOW);
  digitalWrite(motorbspeed, 200);   
}

As of now, when I look at my code in the serial monitor, I get the following; 
LeftHatY: 131
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127

The numbers adjust as I'm moving the joystick around but just keeps going even though I'm not moving the joystick around. Any help would be appreciated, thanks

user10507: I found three issues:

You don't have a # before the include on line 1.
There is no } at the end of the void loop().
You forgot to include an if statement for when the joystick is idle.

Try this code:
#include <PS3USB.h>

    // Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
                  //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printAngle;
uint8_t state = 0;

int motora1 = 4;
int motora2 = 7;
int motoraspeed = 6;
int motorb1 = 3;
int motorb2 = 2;
int motorbspeed = 5;


void setup() {
    Serial.begin(115200);
#if !defined(__MIPSEL__)
    while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
    if (Usb.Init() == -1) {
        Serial.print(F("\r\nOSC did not start"));
        while (1); //halt
    }
    Serial.print(F("\r\nPS3 USB Library Started"));
    pinMode(motora1, OUTPUT);
    pinMode(motora2, OUTPUT);
    pinMode(motoraspeed, OUTPUT);
    pinMode(motorb1, OUTPUT);
    pinMode(motorb2, OUTPUT);
    pinMode(motorbspeed, OUTPUT);
    delay(5000);
}

void loop() {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

        if (PS3.getAnalogHat(LeftHatY) == 0) { //go forward
            Serial.print(F("\r\nLeftHatY: "));
            Serial.print(PS3.getAnalogHat(LeftHatY));
            digitalWrite(motora1, HIGH);
            digitalWrite(motora2, LOW);
            digitalWrite(motoraspeed, 255);
            digitalWrite(motorb1, HIGH);
            digitalWrite(motorb2, LOW);
            digitalWrite(motorbspeed, 255);
        } else if (PS3.getAnalogHat(LeftHatY) == 255) { //go backward
            Serial.print(F("\r\nLeftHatY: "));
            Serial.print(PS3.getAnalogHat(LeftHatY));
            digitalWrite(motora1, LOW);
            digitalWrite(motora2, HIGH);
            digitalWrite(motoraspeed, 255);
            digitalWrite(motorb1, LOW);
            digitalWrite(motorb2, HIGH);
            digitalWrite(motorbspeed, 255);
        } else if PS3.getAnalogHat(RightHatX) == 0) { //turn left
            Serial.print(F("\r\RightHatX: "));
            Serial.print(PS3.getAnalogHat(RightHatX));
            digitalWrite(motora1, HIGH);
            digitalWrite(motora2, LOW);
            digitalWrite(motoraspeed, 200);
            digitalWrite(motorb1, LOW);
            digitalWrite(motorb2, HIGH);
            digitalWrite(motorbspeed, 200);
        } else if (PS3.getAnalogHat(RightHatX) == 255) { //turn right
            Serial.print(F("\r\RightHatX: "));
            Serial.print(PS3.getAnalogHat(RightHatX));
            digitalWrite(motora1, LOW);
            digitalWrite(motora2, HIGH);
            digitalWrite(motoraspeed, 200);
            digitalWrite(motorb1, HIGH);
            digitalWrite(motorb2, LOW);
            digitalWrite(motorbspeed, 200);
        } else { //stop moving
            Serial.print(F("\r\RightHatX: "));
            Serial.print(PS3.getAnalogHat(RightHatX));
            Serial.print(F("\r\nLeftHatY: "));
            Serial.print(PS3.getAnalogHat(LeftHatY));
            digitalWrite(motora1, LOW);
            digitalWrite(motora2, LOW);
            digitalWrite(motoraspeed, 0);
            digitalWrite(motorb1, LOW);
            digitalWrite(motorb2, LOW);
            digitalWrite(motorbspeed, 0);
        }
    }
}


10450: <p>I'm having trouble with controlling my car with the PS3 joystick, and there hasn't been any example codes out there. I'm using;</p>

<ul>
<li>PS3USB library from USB_Host_shield_2.0 library</li>
<li>Freetronics H Bridge shield <a href="http://www.freetronics.com.au/collections/shields/products/hbridge-dual-channel-h-bridge-motor-driver-shield#.VXMqXUJJmgM" rel="nofollow">http://www.freetronics.com.au/collections/shields/products/hbridge-dual-channel-h-bridge-motor-driver-shield#.VXMqXUJJmgM</a></li>
</ul>

<p>This is my code; </p>

<pre><code>include &lt;PS3USB.h&gt;

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include &lt;spi4teensy3.h&gt;
#include &lt;SPI.h&gt;
#endif

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&amp;Usb); // This will just create the instance
//PS3USB PS3(&amp;Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printAngle;
uint8_t state = 0;

int motora1 = 4;
int motora2 = 7;
int motoraspeed = 6;
int motorb1 = 3;
int motorb2 = 2;
int motorbspeed = 5;


void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nPS3 USB Library Started"));
  pinMode(motora1, OUTPUT);
  pinMode(motora2, OUTPUT);
  pinMode(motoraspeed, OUTPUT); 
  pinMode(motorb1, OUTPUT);
  pinMode(motorb2, OUTPUT);
  pinMode(motorbspeed, OUTPUT);  
  delay(5000); 
}

void loop() {
  Usb.Task();

  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    //go forward
     if (PS3.getAnalogHat(LeftHatY) == 0) {
       Serial.print(F("\r\nLeftHatY: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
         digitalWrite(motora1, HIGH);
          digitalWrite(motora2, LOW);
          digitalWrite(motoraspeed, 255);
        digitalWrite(motorb1, HIGH);
        digitalWrite(motorb2, LOW);
        digitalWrite(motorbspeed, 255);  
}

//go backward
if (PS3.getAnalogHat(LeftHatY) == 255) {
       Serial.print(F("\r\nLeftHatY: "));
      Serial.print(PS3.getAnalogHat(LeftHatY));
           digitalWrite(motora1, LOW);
  digitalWrite(motora2, HIGH);
  digitalWrite(motoraspeed, 255);
  digitalWrite(motorb1, LOW);
  digitalWrite(motorb2, HIGH);
  digitalWrite(motorbspeed, 255);  
}

//turn left
if (PS3.getAnalogHat(RightHatX) == 0) {
       Serial.print(F("\r\RightHatX: "));
      Serial.print(PS3.getAnalogHat(RightHatX));
           digitalWrite(motora1, HIGH);
  digitalWrite(motora2, LOW);
  digitalWrite(motoraspeed, 200);
  digitalWrite(motorb1, LOW);
  digitalWrite(motorb2, HIGH);
  digitalWrite(motorbspeed, 200);   
}

   //turn right
   if (PS3.getAnalogHat(RightHatX) == 255) {
       Serial.print(F("\r\RightHatX: "));
      Serial.print(PS3.getAnalogHat(RightHatX));
          digitalWrite(motora1, LOW);
  digitalWrite(motora2, HIGH);
  digitalWrite(motoraspeed, 200);
  digitalWrite(motorb1, HIGH);
  digitalWrite(motorb2, LOW);
  digitalWrite(motorbspeed, 200);   
}
</code></pre>

<p>As of now, when I look at my code in the serial monitor, I get the following; </p>

<pre><code>LeftHatY: 131
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 130
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
LeftHatY: 131
RightHatX: 127
</code></pre>

<p>The numbers adjust as I'm moving the joystick around but just keeps going even though I'm not moving the joystick around. Any help would be appreciated, thanks</p>
 10507: <p>I found three issues:</p>

<ol>
<li>You don't have a <code>#</code> before the include on line 1.</li>
<li>There is no <code>}</code> at the end of the <code>void loop()</code>.</li>
<li>You forgot to include an if statement for when the joystick is idle.</li>
</ol>

<p>Try this code:</p>

<pre><code>#include &lt;PS3USB.h&gt;

    // Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include &lt;spi4teensy3.h&gt;
#include &lt;SPI.h&gt;
#endif

USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&amp;Usb); // This will just create the instance
                  //PS3USB PS3(&amp;Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printAngle;
uint8_t state = 0;

int motora1 = 4;
int motora2 = 7;
int motoraspeed = 6;
int motorb1 = 3;
int motorb2 = 2;
int motorbspeed = 5;


void setup() {
    Serial.begin(115200);
#if !defined(__MIPSEL__)
    while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
    if (Usb.Init() == -1) {
        Serial.print(F("\r\nOSC did not start"));
        while (1); //halt
    }
    Serial.print(F("\r\nPS3 USB Library Started"));
    pinMode(motora1, OUTPUT);
    pinMode(motora2, OUTPUT);
    pinMode(motoraspeed, OUTPUT);
    pinMode(motorb1, OUTPUT);
    pinMode(motorb2, OUTPUT);
    pinMode(motorbspeed, OUTPUT);
    delay(5000);
}

void loop() {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

        if (PS3.getAnalogHat(LeftHatY) == 0) { //go forward
            Serial.print(F("\r\nLeftHatY: "));
            Serial.print(PS3.getAnalogHat(LeftHatY));
            digitalWrite(motora1, HIGH);
            digitalWrite(motora2, LOW);
            digitalWrite(motoraspeed, 255);
            digitalWrite(motorb1, HIGH);
            digitalWrite(motorb2, LOW);
            digitalWrite(motorbspeed, 255);
        } else if (PS3.getAnalogHat(LeftHatY) == 255) { //go backward
            Serial.print(F("\r\nLeftHatY: "));
            Serial.print(PS3.getAnalogHat(LeftHatY));
            digitalWrite(motora1, LOW);
            digitalWrite(motora2, HIGH);
            digitalWrite(motoraspeed, 255);
            digitalWrite(motorb1, LOW);
            digitalWrite(motorb2, HIGH);
            digitalWrite(motorbspeed, 255);
        } else if PS3.getAnalogHat(RightHatX) == 0) { //turn left
            Serial.print(F("\r\RightHatX: "));
            Serial.print(PS3.getAnalogHat(RightHatX));
            digitalWrite(motora1, HIGH);
            digitalWrite(motora2, LOW);
            digitalWrite(motoraspeed, 200);
            digitalWrite(motorb1, LOW);
            digitalWrite(motorb2, HIGH);
            digitalWrite(motorbspeed, 200);
        } else if (PS3.getAnalogHat(RightHatX) == 255) { //turn right
            Serial.print(F("\r\RightHatX: "));
            Serial.print(PS3.getAnalogHat(RightHatX));
            digitalWrite(motora1, LOW);
            digitalWrite(motora2, HIGH);
            digitalWrite(motoraspeed, 200);
            digitalWrite(motorb1, HIGH);
            digitalWrite(motorb2, LOW);
            digitalWrite(motorbspeed, 200);
        } else { //stop moving
            Serial.print(F("\r\RightHatX: "));
            Serial.print(PS3.getAnalogHat(RightHatX));
            Serial.print(F("\r\nLeftHatY: "));
            Serial.print(PS3.getAnalogHat(LeftHatY));
            digitalWrite(motora1, LOW);
            digitalWrite(motora2, LOW);
            digitalWrite(motoraspeed, 0);
            digitalWrite(motorb1, LOW);
            digitalWrite(motorb2, LOW);
            digitalWrite(motorbspeed, 0);
        }
    }
}
</code></pre>
