Compile Errors for Included Files

I am having problems compiling a file that contains Particle defined functions and variables. I copied a section of code that works perfectly fine in a code.ino file, but when I copy and paste the class definition in a .cpp file, I get the following errors:

LEDBlink.cpp: In constructor ‘LEDBlink::LEDBlink(int, unsigned int)’:
LEDBlink.cpp:26:19: error: ‘OUTPUT’ was not declared in this scope
pinMode(_Pin, OUTPUT); //Define Pin as output
^

LEDBlink.cpp:26:25: error: ‘pinMode’ was not declared in this scope
pinMode(_Pin, OUTPUT); //Define Pin as output
^

LEDBlink.cpp:27:33: error: ‘digitalWrite’ was not declared in this scope
digitalWrite(_Pin, _ledState); //LED off
^

LEDBlink.cpp:28:20: error: ‘millis’ was not declared in this scope
_time = millis(); //set initial time
^

LEDBlink.cpp: In member function ‘void LEDBlink::update()’:
LEDBlink.cpp:36:16: error: ‘millis’ was not declared in this scope
if((millis() - _time) > _delay)
^

LEDBlink.cpp:39:37: error: ‘digitalWrite’ was not declared in this scope
digitalWrite(_Pin, _ledState); //Write LED State
^

LEDBlink.cpp: In member function ‘void LEDBlink::on()’:
LEDBlink.cpp:48:33: error: ‘digitalWrite’ was not declared in this scope
digitalWrite(_Pin, _ledState);
^

LEDBlink.cpp: In member function ‘void LEDBlink::off()’:
LEDBlink.cpp:55:33: error: ‘digitalWrite’ was not declared in this scope
digitalWrite(_Pin, _ledState);
^

Any help is appreciated!

@ilehrman, you are most likely missing an #include "application.h" at the top of your file! :wink:

Thank you! That worked. What functions are in the application.h file? I didn’t see any documentation on it in the particle docs.

@ilehrman, application.h is like Arduino’s arduino.h which gets included in most .h or .cpp files. Wwhen using the web IDE with a .ino file, the IDE does that #include invisibly. For .cpp files, you need to add it explicitly. However, as you pointed out, it’s not really documented!

1 Like

Again, Thank you!

1 Like