[SOLVED]Using Servo Library in a Library

Hi,
I’m converting the subroutines I wrote for a robot I built into a library so I can modify it for all my sketches at once. (Why else build a library?) The original sketch worked and my bare bones library compiles without the “_setServo()” function. Once I uncomment the function and the call to the function I get:

Arduino: 1.6.4 (Windows 8.1), TD: 1.23, Board: "Arduino Uno"

C:\~Personal data omitted~\Arduino\libraries\CheapHex\CheapHex.cpp: In member function 'void CheapHex::_setServo()':
C:\~Personal data omitted~\Arduino\libraries\CheapHex\CheapHex.cpp:220:3: error: 'Middle' was not declared in this scope
   Middle.write(_mVal);
   ^
C:\~Personal data omitted~\Arduino\libraries\CheapHex\CheapHex.cpp:221:3: error: 'Left' was not declared in this scope
   Left.write(_lVal);
   ^
C:\~Personal data omitted~\Arduino\libraries\CheapHex\CheapHex.cpp:222:3: error: 'Right' was not declared in this scope
   Right.write(_rVal);
   ^
Error compiling.

EDIT: I’d like to have this work without initializing servos externally.
Here is my stub code, I’m compiling with the Arduino IDE and running on an Arduino Uno.

#include <Arduino.h>	
#include <Servo.h>
#include "CheapHex.h"       //the name of my library

CheapHex::CheapHex(byte _lPin, byte _rPin, byte _mPin){      //attach servos
	Servo Left;
	Servo Right;
	Servo Middle;
	Left.attach(_lPin);
	Right.attach(_rPin);
	Middle.attach(_mPin);
	_setServo();
}

void CheapHex::_setServo(){   //send the servos their next positions
  
  Middle.write(_mVal);
  Left.write(_lVal);
  Right.write(_rVal);
  }

Take a look at a normal sketch that creates Servo objects. When is the attach() method called? When is (or would) it be called in your sketch?

Think about when things happen with respect to when init() gets called to get the hardware ready.

Here is my stub code

Well, some of it, anyway. You did not post the sketch which, I'm guessing, does not #include Servo.h.

Found it. I moved the “Servo Left; Servo Right; and Servo Middle;” objects to the .h file and everything compiles fine. Servo is apparently treated as the data type.

PaulS:
You did not post the sketch which, I’m guessing, does not #include Servo.h.

You could guess that, but the sketch contains very little else

#include <Servo.h>
#include "CheapHex.h"


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}