Error: "has not been declared"

In short, I'm trying to write a program to control a cell phone to start my car. It works well so I wanted to try and put it into a library. I have been successful clearing error messages, but this one I cant seem to get passed. I believe it is because I am trying to pass multiple parameters in the constructor. However, I can't figure out why I keep getting an error message. The message is "hangUpPin has not been declared".

Here is my header file:

/*
  CarPhone.cpp - Library using a blackberry to end and start calls
  Created by Mitchell W. Duncan, February 10, 2013.
  Released into the public domain.
*/

#ifndef CarPhone_h
#define CarPhone_h


#include "Arduino.h"
#include <inttypes.h>

class CarPhone
{
  public:
	CarPhone(int vibratePin, int hangUpPin, int callBackPin, int carStartPin);
	void hangUp();
	void startStopCar(boolean onOff);
	void checkForStart();
	void callReturn();
	int isVib();
  private:
	int _vibratePin;
	int _hangUpPin;
	int _callBackPin;
	int _carStartPin;
};

#endif

and here is the exerpt of my .cpp file

/*
  CarPhone.cpp - Library using a blackberry to end and start calls
  Created by Mitchell W. Duncan, February 10, 2013.
  Released into the public domain.
*/



#include "CarPhone.h"


CarPhone::CarPhone(int vibratePin, int hangUpPin, int callBackPin, int carStartPin)
{
        pinMode(vibratePin, INPUT);
	_vibratePin = vibratePin;
	
	pinMode(hangUpPin, OUTPUT);
	_hangUpPin = hangUpPin;
	
	pinMode(callBackPin, OUTPUT);
	_callBackPin = callBackPin;
	
	pinMode(carStartPin, OUTPUT);
	_carStartPin = carStartPin;

}

I just included the constructor of my .cpp file because I don't want to bomb ya with code.

Also, here is how I initialized the object in my .ino file

#include <CarPhone.h>

void setup()
{
  Serial.begin(9600);
  CarPhone blackberry (A0, 2, 3, 7);
}

My error messages are:

In file included from CarStarter_WL.ino:1:
CarPhone.h:16: error: 'hangUpPin' has not been declared
CarPhone.h:16: error: 'callBackPin' has not been declared
CarPhone.h:16: error: 'carStartPin' has not been declared

Again, any help will be well appreciated! Thanks!
-Mitch

Strangely, if I put them all in one file it compiles just fine:

class CarPhone
{
public:
  CarPhone(int vibratePin, int hangUpPin, int callBackPin, int carStartPin);
  void hangUp();
  void startStopCar(boolean onOff);
  void checkForStart();
  void callReturn();
  int isVib();
private:
  int _vibratePin;
  int _hangUpPin;
  int _callBackPin;
  int _carStartPin;
};


CarPhone::CarPhone(int vibratePin, int hangUpPin, int callBackPin, int carStartPin)
{
  pinMode(vibratePin, INPUT);
  _vibratePin = vibratePin;

  pinMode(hangUpPin, OUTPUT);
  _hangUpPin = hangUpPin;

  pinMode(callBackPin, OUTPUT);
  _callBackPin = callBackPin;

  pinMode(carStartPin, OUTPUT);
  _carStartPin = carStartPin;
}

void setup()
{
  Serial.begin(9600);
  CarPhone blackberry (A0, 2, 3, 7);
}

void loop() {}

Do you have any idea when your constructor will be called, relative to when init() is called to set up the hardware?

If you can not answer definitively that the constructor will be called after init() (and you can't because it isn't), then you should not be diddling with the hardware (via the pinMode() calls) in the constructor.

Translation : put a begin (or any other suitably named) function in your class then call it in setup() in your program in the same way that Serial.begin() is called. This ensures that it will be called after the hidden init() function is called and it will be safe to diddle with the hardware.

Any idea about the original question though?

Any idea about the original question though?

I'd be interested in investigating further, if only you had posted ALL of your code.

UKHeliBob:
Translation : put a begin (or any other suitably named) function in your class then call it in setup() in your program in the same way that Serial.begin() is called. This ensures that it will be called after the hidden init() function is called and it will be safe to diddle with the hardware.

Thank you so much! My error was that I was using pinMode() before void setup(). I'm still new to arduino (this is my first project actually, I'm just taking what I know from C and Java, but I haven't written classes in C.) Also my other error was since I was working with my files in tabs, they were all in the same project folder (instead of the library folder like it probably should), so instead of including it like "#include <class.h>" I needed to use "#include "class.h". Once I got through some of my other general error messages, the program worked perfectly!

PaulS:
I'd be interested in investigating further, if only you had posted ALL of your code.

Ill post the code that I have right now(so if other people had the same issue), but it is still somewhat of a mess(ran out of time), so It has work to be redone

Header: CarPhone.h

/*
  CarPhone.ch - Header using a blackberry to end and start calls to start and stop a car's engine from afar
  Created by Mitchell W. Duncan, February 10, 2013.
  Released into the public domain.
*/

#ifndef CarPhone_h
#define CarPhone_h


#include "Arduino.h"
#include "inttypes.h"

class CarPhone
{
  public:
        void begin();
	CarPhone(int vibratePin, int hangUpPin, int callBackPin, int carStartPin);
	void hangUp();
	void startStopCar(boolean onOff);
	void checkForStart();
	void callReturn();
	int isVib();
        
  private:
	int _vibratePin;
	int _hangUpPin;
	int _callReturnPin;
	int _carStartPin;
};

#endif

C++ file: CarStarter.cpp

/*
  CarPhone.cpp - Library using a blackberry to end and start calls
  Created by Mitchell W. Duncan, February 10, 2013.
  Released into the public domain.
*/

#include "CarPhone.h"


CarPhone::CarPhone(int vibratePin, int hangUpPin, int callReturnPin, int carStartPin)
{
        _vibratePin = vibratePin;
	_hangUpPin = hangUpPin;
	_callReturnPin = callReturnPin;
        _carStartPin = carStartPin;
}




void CarPhone::begin()
{
  pinMode(_vibratePin, INPUT);
  pinMode(_hangUpPin, OUTPUT);
  pinMode(_callReturnPin, OUTPUT);
  pinMode(_carStartPin, OUTPUT);
}




void CarPhone::hangUp() //code to hang up phone call 
{
  Serial.println("HANGUP");                // tells serial console / debugger that the arduino has gotten the hangup code
  delay(800);                              // waits for second vibrate to finish, not necessary, but I like it. 
  digitalWrite(_hangUpPin, HIGH);           // Essentially pushes the hang up button  
  delay(500);                              // holds it for a half second for good measure (like human finger)
  digitalWrite(_hangUpPin, LOW);            // releases hang up button on phone
  
}



void CarPhone::startStopCar(boolean onOff)         //code to start or stop the car - TRUE= on, FALSE = off
{
  int numToPressFob = 2;                // number to push buttons is default to turn it on
  
  if(!onOff)                           //if the car needs to be tuned off, press the fob 3 times
  {
    numToPressFob = 3;
    Serial.println("THE CAR IS SHUTTING DOWN");
  }
   else
   {
     Serial.println("THE CAR IS TURNING ON");
   }
    
   
  for(int s = 0; s < numToPressFob; s++)             //runs the chunk of code twice
  {
   digitalWrite(_carStartPin, HIGH);      //pushes the starter pin
   delay(900);                           //waits 9 tenths of a second
   digitalWrite(_carStartPin, LOW);       //stops pushing the starter pin
   delay(1200);                          //waits a second before it runs again
  } 
}





void CarPhone::checkForStart() //code that checks for +5V on the phone for more than X seconds to be sure that the car successfully started
{

}

void CarPhone::callReturn()   // code that pushes the #2 button on the cell phone to speed dial my number back
{
  Serial.println("CALLING BACK");      //calling back in serial console for debugging purposes
  delay (1000);                        //waits a second for good measure  
  
  for(int i = 0; i < 2; i++)           //runs this twice
  {
  digitalWrite(_hangUpPin, HIGH);       //pushes the hang up button (to quit any programs)
  delay(300);                          //holds it pushed for 3 tenths of a seconnd
  digitalWrite(_hangUpPin, LOW);        //releases the button 
  }
  
  
  digitalWrite(_callReturnPin, HIGH);     //pushes the call back button
  delay(1000);                         //waits speed dial push time
  digitalWrite(_callReturnPin, LOW);      //stops pushing the button
  delay(17000);                        //waits 17 seconds (really annoying since there is a message about low funds in account)
  
  hangUp();
  
}





int CarPhone::isVib()
{
   int currentV = analogRead(_vibratePin);           //sets the current voltage to whatever the vibrator is doing
   if ((currentV >= 31) && (currentV <= 38))        //if the vibrate pin is vibrating
   {
     return 1;                                      // return 1
   }
   else if ((currentV <=31) && (currentV >= 38))    //if the vibration is stopping
   {  
     return -1;                                     // return -1
   }
   else                                             // otherwise
  {
    return 0;                                       //return 0
  }   
}

CarStarter_With_Library.ino

#include "CarPhone.h"

CarPhone blackberry(A0, 2, 3, 7);               //creates the phone object (I'm using a blackberry, so I called it blackberry)




void setup()                                    //sets everything up
{
  
  Serial.begin(9600);                           //gets the serial monitor ready for debugging sequences
  blackberry.begin();                           //sets the input & output pins for the arduino
 Serial.println("THE PROGRAM HAS BEGUN!");
}







void loop()
{
  int timesVib = 0;                                //counter for times it has vibrated
  
  long beginTime = 0;                              //int used for later to test to see for a timeout
  long timeOutTime = 3000;                         //how long you want the timeout to be
  long shutOffTime = (10 * 60000);                  //how long between the first call and second call you want to shut off the car, replace 8 for X minutes
  
  
  if (blackberry.isVib() == 1)          //if the vibrate pin is vibrating
  {
    
    
    beginTime = millis();                            //record the beginning time
    timesVib++;                                      //tell the counter that it has vibrated once
    delay(2300);                                     //wait for it to finish vibrating
    
    
    
    
   
    do{
    }while(blackberry.isVib() == -1);                            //update the current voltage to currentV until it is in the acceptable range to continue (saying it is vibrating again)
    
    
    
    

    if (timesVib = 1 && ((millis() - beginTime) < timeOutTime))         //if it has vibrated twice AND it hasn't timed out yet, go ahead and start the car
     {   
     
       
       blackberry.hangUp();                                                       //calls the hang up method
       blackberry.startStopCar(1);                                                //calls the start car method
       delay(5000);                                                               // waits 5 seconds to let the user get off the phone and to let the cellular circuits to clear
       //check for run
       blackberry.callReturn();                                                   //calls my number back                                          
     }
     
     
     
     
     
     
     Serial.println("Waiting to see if the user wants to Shut off car");
     while((millis() - beginTime) < shutOffTime)
      {
        
        
        if(blackberry.isVib() == 1)
        {
        blackberry.hangUp();
        blackberry.startStopCar(0);
        delay(5000);
        blackberry.callReturn();
        delay(2000);
        blackberry.callReturn();
        break;
        }
      }   
    
    Serial.println("EOL \n");  
    
     
     }
   
  }

Thank you again for all your help! The community is great! Once I completely finish my project, I'll be sure to post it in the projects sub forum. I'm building a GSM remote start for my car using the existing remote starting system. However, I didn't want to pay for another service, so I'm using prepaid and it'll cost ~ $0.33 a month to keep the number active. It doesn't use minutes since the phone is never accepting a call. I'll talk about it more when I post the actual project though. Thanks again for all the help!
-Mitch

johncc:
Any idea about the original question though?

PaulS:

Any idea about the original question though?

I'd be interested in investigating further, if only you had posted ALL of your code.

I'm not the OP.

Is there a forum setting that automatically removes the author when quoted? --Or do you do that explicitly each time you reply.

but I haven't written classes in C.

And you never will. Classes are a feature of C++.

Is there a forum setting that automatically removes the author when quoted? --Or do you do that explicitly each time you reply.

If you are talking to me, I only copy and paste the part I want to quote. I don't often use the quote option, because that needs to be invoked before starting to type a reply. I sometimes like to respond in a different order, too.

Or quote stuff somewhat out of context. 8)

PaulS:
I don't often use the quote option, because that needs to be invoked before starting to type a reply.

If you scroll down through previous replies while writing a reply you will see a little red "Insert Quote" link at the top right of each previous reply. Clicking on that link will insert the quote at the current cursor position in your reply.