PTZ Commands PS3

ok here Is my code. the stop command just prints out all the time. like the hex example previous posts

where the stop command comes after, maybe it cant be done as the ps3 analog doesn't return to a zero position.

[/[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;

//=========================
//Start Pelco-D section 
//=========================
//
//set some Pelco command vars
int PelcoMaxSpeed = 200;                           
int PelcoMinSpeed = 0;
byte CurrCameraAddress = 01;
byte SynchByte = 0xFF;                
byte PanSpeed = 00;
byte TiltSpeed = 00;
byte ZoomSpeed = 00;

/*
command 1
  7  Sense 
  6  Reserved
  5  Reserved
  4  Auto/Manual Scan
  3  Camera On/Off
  2  Iris Closed
  1  Iris Open
  0  Focus Near
*/
byte command1 = B00000000;
 

//set up some working vars so we don't need to calculate them every loop itteration
int rightRange = 0;
int leftRange = 0;
int upRange = 0;
int downRange = 0;
int zoomInRange = 0;
int zoomOutRange = 0;



//=========================
//end Pelco-D setup 
//=========================

void stop() {
     Serial2.write(byte(SynchByte));         // Synch Byte
            Serial2.write(byte(CurrCameraAddress)); // Camera Address
            Serial2.write(byte(0x00));
            Serial2.write(byte(0x00));                // no command
            Serial2.write(byte(0x00));
            Serial2.write(byte(0x00));                // all stop
           byte checkSum = (byte(CurrCameraAddress) + byte(00) + byte(0x00) + byte(0x00) + byte(00)) %256;
           Serial2.write(byte(checkSum));          //check sum is the sum of bytes (excluding the synchronization byte) modulo 256
           delay (2);  
}
           
void setup() {
  Serial.begin(115200);
  Serial2.begin(9600);
  
  
  CurrCameraAddress = 00;  
  
 // while (CurrCameraAddress <= 3)             // send the set zoom speed command to all 3 cameras
  
  {
  CurrCameraAddress = CurrCameraAddress + 01;

  }
  
#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(L2,INPUT);
}



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));
      if (PS3.PS3Connected) { // The Navigation controller only have one joystick
        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
          
    // stat L2 program    
    
      
      
  if (PS3.getAnalogButton(L2) >0 & PS3.getAnalogButton(L2) <63 || PS3.getButtonClick(UP)) 
      
      if (PS3.getButtonClick(L2)==HIGH) {
      Serial.print(F("\r\nL2: "));
      Serial.print(PS3.getAnalogButton(L2)); 
                
       /*
command 2
  7  Focus Far 
  6  Zoom Wide
  5  Zoom Tele
  4  Down
  3  Up
  2  Left
  1  Right
  0  Always 0
*/ 
byte command2 = B00000000;
 
              
       PanSpeed = PS3.getAnalogButton(L2) ; 
       TiltSpeed = PS3.getAnalogButton(UP); 
              
            command1 = B00000000;     
            command2 = B00000100;      
            
            Serial2.write(byte(SynchByte));         // Synch Byte - byte 1
            Serial2.write(byte(CurrCameraAddress)); // Camera Address - byte 2
            Serial2.write(byte(command1));                // byte 3
            Serial2.write(byte(command2));                // byte 4
            Serial2.write(byte(PanSpeed));                // byte 5
            Serial2.write(byte(TiltSpeed));                // byte 6
            byte checkSum = (byte(CurrCameraAddress) + byte(command1) + byte(command2) + byte(PanSpeed) + byte(TiltSpeed)) %256;
           Serial2.write(byte(checkSum));          //check sum is the sum of bytes (excluding the synchronization byte) modulo 256 
           
        
             if (PS3.getButtonClick(L2)==LOW){
          stop();
            }
  }  
         
           
}

code][/code]