"Not Declared In This Scope": Rocket Launching PS3 Remote Controlled Bot

Can anybody explain to me what is going on with my code? I’m getting a, “Not Declared In This Scope” response every time I try to compile it.

...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 || PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0)
    {
      if(Serial.print(PS3.getAnalogHat(LeftHatX)) > 0)
      {
        Servo_Motor_UnTurn();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatX)) < 0)
      {
        Servo_Motor_Turn();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) > 0)
      {
        Forward();
      }...

I’m using code from,

for my PS3 controls…

Here’s the example code they use to show how to print button responses:

/*
 Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
 For more information visit my blog: http://blog.tkjelectronics.dk/ or 
 send me an e-mail:  kristianl@tkjelectronics.com
 */

#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);            
        }         
      } 

      if(PS3.getButtonClick(L1))
        Serial.print(F("\r\nL1"));  
      if(PS3.getButtonClick(L3))
        Serial.print(F("\r\nL3")); 
      if(PS3.getButtonClick(R1))
        Serial.print(F("\r\nR1"));             
      if(PS3.getButtonClick(R3))
        Serial.print(F("\r\nR3"));

      if(PS3.getButtonClick(SELECT)) {
        Serial.print(F("\r\nSelect - ")); 
        Serial.print(PS3.getStatusString());        
      } 
      if(PS3.getButtonClick(START)) {
        Serial.print(F("\r\nStart"));              
        printAngle = !printAngle;
      }                           
    }
    if(printAngle) {
      Serial.print(F("\r\nPitch: "));               
      Serial.print(PS3.getAngle(Pitch));                  
      Serial.print(F("\tRoll: ")); 
      Serial.print(PS3.getAngle(Roll));
    }
  }
  else if(PS3.PS3MoveConnected) {
    if(PS3.getAnalogButton(T_ANALOG) > 0) {
      Serial.print(F("\r\nT: ")); 
      Serial.print(PS3.getAnalogButton(T_ANALOG)); 
    } 
    if(PS3.getButtonClick(PS)) {
      Serial.print(F("\r\nPS"));
      PS3.disconnect();
    } 
    else {
      if(PS3.getButtonClick(SELECT)) {
        Serial.print(F("\r\nSelect"));
        printTemperature = !printTemperature;
      } 
      if(PS3.getButtonClick(START)) {
        Serial.print(F("\r\nStart"));
        printAngle = !printAngle;                          
      } 
      if(PS3.getButtonClick(TRIANGLE)) {            
        Serial.print(F("\r\nTriangle"));
        PS3.moveSetBulb(Red);
      } 
      if(PS3.getButtonClick(CIRCLE)) {
        Serial.print(F("\r\nCircle"));
        PS3.moveSetBulb(Green);
      } 
      if(PS3.getButtonClick(SQUARE)) {
        Serial.print(F("\r\nSquare"));
        PS3.moveSetBulb(Blue);
      } 
      if(PS3.getButtonClick(CROSS)) {
        Serial.print(F("\r\nCross"));
        PS3.moveSetBulb(Yellow);
      } 
      if(PS3.getButtonClick(MOVE)) {     
        PS3.moveSetBulb(Off);                        
        Serial.print(F("\r\nMove"));
        Serial.print(F(" - ")); 
        Serial.print(PS3.getStatusString());
      }
    }
    if(printAngle) {
      Serial.print(F("\r\nPitch: "));               
      Serial.print(PS3.getAngle(Pitch));                  
      Serial.print(F("\tRoll: ")); 
      Serial.print(PS3.getAngle(Roll));
    }
    else if(printTemperature) {
      Serial.print(F("\r\nTemperature: "));
      Serial.print(PS3.getTemperature());
    }
  }
}

And here is my code in its entirety:

//STILL NEEDS LAUNCH CODE!!!!!!!!!!


//STILL NEEDS LAUNCH CODE!!!!!!!!!!



#include <PS3BT.h>
int pinI1=8;//define I1 interface, Motor Pin
int pinI2=11;//define I2 interface, Motor Pin 
int speedpinA=9;//enable Motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable ignition
int speed =1000;//define the spead of motor
const int pingPin=7;//UltraSonic Sensor Pin. let it be noted that const means constant
int servopin = 4;//Servo 1's Pin
int servopin2 = 5;
int servopin3 = 6;
int pulse = 1500;//Servo
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(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(servopin, OUTPUT);
  pinMode(servopin2, OUTPUT);
  pinMode(servopin3, OUTPUT);
  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 Forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  digitalWrite(pinI2,LOW);
  digitalWrite(pinI1,HIGH);
}

void Backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  digitalWrite(pinI2,HIGH);
  digitalWrite(pinI1,LOW);
}

void Stop()
{
  digitalWrite(speedpinA, LOW);
  delay(1000);
}

void Servo_Motor_Turn()
{  
  digitalWrite(servopin, HIGH);
  delayMicroseconds(pulse);
}

void Servo_Motor_UnTurn()
{
  digitalWrite(servopin, LOW);
  delayMicroseconds(pulse);
}

void Servo_Lift()
{
  digitalWrite(servopin2, HIGH);
  delayMicroseconds(pulse);
}

void Servo_UnLift()
{
  digitalWrite(servopin2, LOW);
  delayMicroseconds(pulse);
}

void Servo_Swivel()
{
  digitalWrite(servopin3, HIGH);
  delayMicroseconds(pulse);
}

void Servo_UnSwivel()
{
  digitalWrite(servopin3, LOW);
  delayMicroseconds(pulse);
}

long Sensor_loop()//this funtion is going to need to be played with
{
  long microseconds, inches;//establishes variables: duration(microseconds) and distance(inches)

  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  microseconds=pulseIn(pingPin, HIGH);

  //code to convert time to distance
  inches= long (microseconds/74/2);
  //code to print distance values
  Serial.print(inches);
  Serial.print("in, ");
  return inches;

  delay(100);
}

void Ignition()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  digitalWrite(pinI2,LOW);
  digitalWrite(pinI1,HIGH);
}

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 || PS3.getAnalogButton(L2_ANALOG) > 0 || PS3.getAnalogButton(R2_ANALOG) > 0)
    {
      if(Serial.print(PS3.getAnalogHat(LeftHatX)) > 0)
      {
        Servo_Motor_UnTurn();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatX)) < 0)
      {
        Servo_Motor_Turn();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) > 0)
      {
        Forward();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) < 0)
      { 
        Backward();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) == 0)
      {
        Stop();
      }
      if(Serial.print(PS3.getAnalogHat(RightHatX)) > 0)
      {
        Servo_Swivel();
      }
      if (Serial.print(PS3.getAnalogHat(RightHatX)) < 0)
      {
        Servo_UnSwivel();
      }
      if (Serial.print(PS3.getAnalogHat(RightHatY)) > 0)
      {
        Servo_Lift();
      }
      if (Serial.print(PS3.getAnalogHat(RightHatY)) < 0)
      { 
        Servo_UnLift();
      }
      if (Serial.print(PS3.getAnalogButton(L2_ANALOG)) > 0)
      {
        Ignition();
      }
    }
  }
  else
  {
    long inches = Sensor_loop();
    {
      if (inches>6)
      {
        Forward();
        delay(2000);
      }

      else if (inches<=6)
      {
        Stop();
        Servo_Motor_Turn();
        Backward();
        delay(2000);
        Stop();
        Servo_Motor_UnTurn();
        delay(2000);
        Stop();
      }
    }
  }
}
#include <PS3BT.h>

Which you got from WalMart?

USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so

How is the compiler supposed to know what these are?

I'm getting a, "Not Declared In This Scope" response every time I try to compile it.

I’m 100% certain that the compiler is telling you WHAT is not declared in this scope, AND what that scope is. There is NOTHING complicated about the message. The ONLY problem is that ONLY you can see the actual message.

You're right, I wasn't clear enough... It's finding PS3BT.h just fine and everything else in the lib. The problem is, it's not recognizing the L2/R2 Analog bit. With out them, it works just fine. It's only pulling info from those two buttons that it doesn't want to do.

check whether the missing names are actually in the .h file that you are using.

They may not be, if you have an obsolete or incompatible version of it.

If that was the case, wouldn't I get the same error in the example code?

If that was the case, wouldn't I get the same error in the example code?

Hard to say. Your feet are a blur with all that fancy tap dancing your are doing to avoid posting the ACTUAL messages. Sit down!

Post the EXACT error messages.

All it says is, "BotCodeMach4: 141: error 'R2_ANALOG' was not declared in this scope'"
And repeats the message for L2

So, where do you think that R2_ANALOG or L2_ANALOG are declared?

PS3BT.h ...look at the example that came with the lib. It only appears in the void loop when it's being used, but is otherwise undeclared... Just like mine... Yet the example code works(it prints out buttons as you press them).

To that point, LeftHat and RightHat aren't giving me undeclared errors. Why would L2 and R2? They're all found in PS3BT.h and all work just fine in the example.

PS3BT.h …look at the example that came with the lib.

Well, I would have, if you had posted a link to the library.

I did... I posted a section of my code(the problem area), the example they gave, and then my code in full. I also left the link to where I got the lib from. That was all in my first two posts in the thread.

I also left the link to where I got the lib from.

No, that was a link to a you tube video.

The link is in the video's description. But to save time, here it is too:GitHub - felis/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.

OK. Final question:

look at the example that came with the lib.

There are many examples that come with the library. Specifically, which one uses (successfully) L2_ANALOG?

Again, I already posted the example code that the lib offered, it is the second set of code in my opening post to the thread. In the lib it’s called PS3BT.

I copied the sketch you posted in your first post. It fails to compile for me. The ONLY place in the whole library where L2_ANALOG is mentioned is in a comment. Ditto for R2_ANALOG. There are other function calls in the example that no longer exist, too, so I can only surmise that the sketch goes with an older version of the library.

I figured it out, I had to drop the "_ANALOG"