I'm breaking my head trying to use Servo.h inside of a library I made. The compiler consistently gives me the same error, as if it does not recognize the class, which is included in my library.
I am trying to make a new class, one of it's properties is a Servo object, which I should pass in the constructor. No matter how I try, I keep receiving the same error message when trying to compile my sketch:
In file included from /home/nezah/Arduino/My sketches/CameraShutter/CameraShutter.ino:8:0: /home/nezah/Arduino/libraries/Shutter/Shutter.h:13:19: error: expected ')' before '*' token Shutter(Servo *servo);
It seems that the include statement is ok, as I get a different message if I mess it to go wrong or remove it completely. I already tried to change "" for <> and even copied the source in a folder and use the full path. No change as far as I don't mess it (on purpose). I already read this.
I also tried to pass it as a pointer, using Shutter(Servo* servo)
, Shutter(Servo *servo)
and Shutter(Servo& servo)
. Same error message.
In some arduino.cc forum I read that I rather forget it and avoid using libraries inside other libraries, but I bet this is possible.
Is there anybody so kind as to give me some hints on how to do this?
I leave you part of my .h and .cpp of the library I'm trying to write (which, by the way, turns a servo into a physical button presser but with burst capability).
/*
* Shutter.h - Library to make a photocamera shutter out of a servo
* alternatively it could press any physical button with a servo.
*/
#ifndef Shutter
#define Shutter
#include "Servo.h"
class Shutter {
public:
Shutter(Servo *servo);
Servo getServo();
void shut();
private:
Servo _servo;
}
#endif
And here is my .cpp:
/*
Shutter.cpp - Library for flashing Shutter code.
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#include <Arduino.h>
#include "Servo.h"
#include "Shutter.h"
Shutter::Shutter(Servo *servo) {
_servo = servo;
}
NOTE: If I remove some code and take away the "Servo" part of the constructor, I get an error message on the "getServo()" code. The problem seems to be that the compiler does not recognize "Servo" as a valid type inside my library.
Thanks in advance!