Problem with MegaServo.h library.

Hi!
I am trying to build a hexapod using Mega-2560. I want to use 18 servo motors. I downloaded and placed the MegaServo library in the libraries folder and when i try to run this testing code:

#include <MegaServo.h>
#define NBR_SERVOS 12  // the number of servos, up to 48 for Mega, 12 for other boards
#define FIRST_SERVO_PIN 2 

MegaServo Servos[NBR_SERVOS] ; // max servos is 48 for mega, 12 for other boards
int pos = 0;      // variable to store the servo position 
int potPin = 0;   // connect a pot to this pin.

void setup()
{
  for( int i =0; i < NBR_SERVOS; i++)
    Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200);
}
void loop()
{ 
  pos = analogRead(potPin);   // read a value from 0 to 1023
  for( int i =0; i <NBR_SERVOS; i++) 
    Servos[i].write( map(pos, 0,1023,0,180));   
  delay(15);   
}

I am receiving the following errors:

/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: In function ‘void handle_interrupts(servoTimer_t, volatile uint16_t*, volatile uint16_t*)’:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:96: error: ‘LOW’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:96: error: ‘digitalWrite’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:103: error: ‘HIGH’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:103: error: ‘digitalWrite’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:107: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: At global scope:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:169: error: ‘boolean’ does not name a type
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: In constructor ‘MegaServo::MegaServo()’:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:205: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: In member function ‘uint8_t MegaServo::attach(int, int, int)’:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:219: error: ‘OUTPUT’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:219: error: ‘pinMode’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:226: error: ‘isTimerActive’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: In member function ‘void MegaServo::write(int)’:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:247: error: ‘byte’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:247: error: expected `;' before ‘channel’
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:248: error: ‘channel’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:251: error: ‘map’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:258: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: In member function ‘int MegaServo::read()’:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:273: error: ‘map’ was not declared in this scope
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp: In member function ‘int MegaServo::readMicroseconds()’:
/home/sadanarshad/Downloads/arduino-1.0.5/libraries/MegaServo/MegaServo.cpp:280: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope

Start with the first error. Often when that is fixed many of the others go away.

My guess is that the library is for an older version of the Arduino IDE and the .h file in the library doesn't have #include <Arduino.h> at the top of it. I hope I have the spelling correct. You may also need that in the library's .cpp file - but I am starting to get out of my depth with C/C++ at this stage.

...R

Yes, the library files may still have the older #include "WProgram.h" instead. If so, try replacing that as Robin2 suggests.

Thanks Robin2 :slight_smile:
it compiled successfully.

Hackscribble:
Yes, the library files may still have the older #include "WProgram.h" instead. If so, try replacing that as Robin2 suggests.

Thanks. I couldn't remember what the older version was called.

...R