I am creating my own library for the Arduino and I have the following code:
#include <Arduino.h>
#include <Servo.h>
class ServoMotorController {
public:
ServoMotorController(int servoPin, int motorPin, int angle);
void setAngle(int angle);
void setSpeed(int speed);
private:
Servo servo;
int servoPin;
int servoAngle;
int motorPin;
int motorSpeed;
};
I am getting the error that Servo
does not name a type; however if I do
#include <Servo.h>
#include <ServoMotorController.h>
in my actual Arduino code then I do not get the error. Why is the include statement not working in my C++ lib?
1 Answer 1
This is a symptom of the arduino IDE. libraries can't add other libraries to the include path, but the can use other libs if they have already been included. you can use an error directive so your compiler output is more informative at least
#ifndef Servo_h
#error "ServoMotorController Lib requires Servo.h to be included first to function"
#else
Arduino 1.5.6 beta's new library format has a section for dependencies in the new library.properties file that should allow one library to add another to the include path, but I'm not entirely sure if the functionality is fully implemented yet (its beta after all).
#include <File.h>
and#include "File.h"
.