I'm creating a few classes for a project, which seems so specific that I don't want to keep in the libraries folder. They're mostly working, however, if I want to call any Arduino functions or consts, it will throw errors "is not declared in this scope".
MyClass.cpp: 'HIGH','pinMode' is not declared in this scope.
It wouldn't happen if I put the libraries in libraries folder though. Wondering if there's a way to include arduino functions into sketch folder libraries?
On the contrary, this would detect which Arduino version your library is being compiled in, and uses the appropriate Arduino include file. The name of the arduino library changed ( before version 1.0 it was WProgram.h and since 1.0 it is Arduino.h).
If you're expecting to share your library with others and believe/expect/confirm that your library works with previous Arduino versions (e.g. 0023 ), then put the if/then construct there. If you're not intending to share it with others and/or you're only using 1.0.x and later, it doesn't really matter--you could just use the Arduino.h...
Interesting...
The example is just for showing my problem regarding undeclared functions, so it doesn't have real purpose. However I never thought about the potential problem between constructor and hardware. Thank you for the extra knowledge! So what problems can there be?
Your constructor gets called when the object is instantiated. If that happens at global scope, it will happen before init() is called. You set the pin to be an OUTPUT pin. Then, init() gets called, and it KNOWS that pins are to be INPUT, so it changes the pin to an INPUT pin.
Then, your class tries to turn the LED on and off, and it won't be very bright.