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".
sketch:
#include "MyClass.h"
void setup(){
}
void loop(){
}
MyClass.h
class MyClass{
public:
MyClass(int inp);
int myFun();
};
MyClass.cpp
#include "MyClass.h"
#include <WProgram.h>
MyClass::MyClass(int inp){
pinMode(13,HIGH);
}
error:
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?
AFAIK there is no way to have yout libraries anywhere but in the Arduino-lib-folder. If using unix you could put your libs in your sketch folder and create a link to these libs in your Arduino-lib-folder with ln
. Then you should also see them in your IDE
Actually I just get it to work, by looking into another library :P instead of
#include <WProgram.h>
We should use
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
Which is bad for backward compatibility as I think...
And it's not a problem regarding using libraries in sketch folder. There're some potential problems with sketch folder libraries however.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.