Hello everyone , I'm trying to use sharp Ir library inside .cpp file so when I call a function from that class it will read my Ir sensors.Any suggestion on how to do it ?. Below I posted my code for the .cpp and .h files.
#ifndef SENSORCONTROLLER_CPP
#define SENSORCONTROLLER_CPP
#include "SensorController.h"
SharpIR Centersensor( SharpIR::GP2Y0A41SK0F, A1 );
SharpIR Leftsensor( SharpIR::GP2Y0A41SK0F, A2 );
SharpIR Rightsensor( SharpIR::GP2Y0A41SK0F, A0 );
Encoder SensorController::leftEncoder = Encoder(3, 7);
Encoder SensorController::rightEncoder = Encoder(2, 8);
int SensorController::RightS;
int SensorController::LeftS;
int SensorController::CenterS;
void SensorController::IrReading(){
RightS=Rightsensor.getDistance();
LeftS=Leftsensor.getDistance();
CenterS= Centersensor.getDistance();
}
void SensorController::printSensors(){
Serial.print("L: ");
Serial.print(leftEncoder.read());
Serial.print(" R: ");
Serial.print(SensorController::RightS);
Serial.print(" C: ");
Serial.println(CenterS);}
#endif
//Sensors Object that Includes the two Encoders and three Ir Sensors
#ifndef SENSORCONTROLLER_H
#define SENSORCONTROLLER_H
#include "Arduino.h"
#include "const.h"
#include <Encoder.h>
#include <SharpIR.h>
namespace SensorController {
extern int RightS;
extern int LeftS;
extern int CenterS;
extern Encoder leftEncoder;
extern Encoder rightEncoder;
void IrReading();
void printSensors();
}
#endif
when I call the printsensors function , I get zero values for the sensor I don't why