i want to create a library for a project, and i have to do a analogRead at one moment. I created a library for this, and it compile without any errors. But when i want to call this function, it return me 0, but it is working fine in the .ino file..
Here are my files :
the .ino file
#include <Filoguidage.h>
Filoguidage filoguidage;
int pin = A11;
void setup() {
Serial.begin(115200);
pinMode(pin,INPUT);
filoguidage.init(pin,10,10);
}
void loop() {
int test = filoguidage.getPosition();
Serial.println(test);
}
The .h of my library :
#ifndef Filoguidage_h
#define Filoguidage_h
#include "Energia.h"
class Filoguidage
{
public:
void init(int PinCapteur,int valeurCentrale, int interval);
int getPosition();
private:
int _PinCapteur;
};
#endif
And finally the .cpp :
#include "Energia.h"
#include "Filoguidage.h"
void Filoguidage::init(int PinCapteur,int valeurCentrale,int interval){
int _PinCapteur = PinCapteur;
pinMode(_PinCapteur, INPUT);
}
int Filoguidage::getPosition(){
return analogRead( _PinCapteur );
}
I think thats because pinMode and analogRead are not recognized, but i don't know how to solve it. If somebody can help me i would be very happy, thanks
Aucun commentaire:
Enregistrer un commentaire