Using Servo in a custom header file

I’m trying to port over an Arduino library I made - https://github.com/efatsi/Arduino-Libraries/tree/master/ShotPour.

I first removed lines 10 and 11 in ShotPour.h since I was getting an error like so:

ShotPour.h:10:19: fatal error: Servo.h: No such file or directory
compilation terminated.

However here, I’m calling Servo _servo; and the Spark IDE is not liking this:

In file included from ShotPour.cpp:7:0:
ShotPour.h:26:5: error: 'Servo' does not name a type
ShotPour.cpp: In constructor 'ShotPour::ShotPour(int, int, int, int, int)':
ShotPour.cpp:22:20: error: 'OUTPUT' was not declared in this scope
ShotPour.cpp:22:26: error: 'pinMode' was not declared in this scope
ShotPour.cpp: In member function 'void ShotPour::initialize()':
ShotPour.cpp:31:3: error: '_servo' was not declared in this scope
ShotPour.cpp:34:25: error: 'LOW' was not declared in this scope
ShotPour.cpp:34:28: error: 'digitalWrite' was not declared in this scope
ShotPour.cpp:35:25: error: 'HIGH' was not declared in this scope
ShotPour.cpp: In member function 'void ShotPour::pour()':
ShotPour.cpp:43:24: error: 'LOW' was not declared in this scope
ShotPour.cpp:43:27: error: 'digitalWrite' was not declared in this scope
ShotPour.cpp:45:24: error: 'HIGH' was not declared in this scope
ShotPour.cpp:48:5: error: '_servo' was not declared in this scope
ShotPour.cpp:49:13: error: 'delay' was not declared in this scope
ShotPour.cpp:52:13: error: 'delay' was not declared in this scope
ShotPour.cpp:58:5: error: '_servo' was not declared in this scope
make: *** [ShotPour.o] Error 1

Error: Could not compile. Please review your code.

I know it’s possible to use Servo _servo; within a .ino file in the Spark IDE, but it is possible to do so in a custom header file?

try adding #include "application.h" in your custom header file

Thanks @kennethlimcp. Needed quotes like so #include "application.h" but it worked like a charm!

Was there a section in the documentation that I missed on making those extra files work well?

1 Like

Oops I just typed it off my head. Hahaha.

It was announced some time ago :slight_smile:

Glad you guys got things working! :smile:

Here’s the post for reference:

Thanks,
David