I am far from being an Arduino specialist, so please bear with me if some of my code below is far from correct.
I am writing a sketch in which I need to use 3 instances of the HX711 library, as I am using 3 different weight sensors.
In order to try to clean up the code, I want to put basically all the code using HX711 in my own class.
Here is what my ScaleMeasure.h looks like:
// ScaleMeasure.h
#ifndef _SCALEMEASURE_h
#define _SCALEMEASURE_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include <CmdMessenger.h>
#include "HX711.h"
class ScaleMeasure
{
public:
ScaleMeasure(int Dout, int Clk, float CalibF, int ScaleID);
void Setup();
float Measure();
private:
int _dout_pin;
int _clk_pin;
float _calibration_factor;
byte _scaleID;
HX711 _scale = HX711(_dout_pin, _clk_pin);
};
and .cpp
#include "ScaleMeasure.h"
ScaleMeasure::ScaleMeasure(int Dout, int Clk, float CalibF, int ScaleID)
{
_clk_pin = Clk;
_dout_pin = Dout;
_calibration_factor = CalibF;
_scaleID = ScaleID;
}
void ScaleMeasure::Setup()
{
_scale.power_up();
_scale.set_scale();
_scale.set_scale(_calibration_factor);
_scale.tare();
_scale.read();
}
float ScaleMeasure::Measure()
{
return _scale.get_units(5);
}
but there is obviously something wrong, as a call to the constructor lock the rest of the program. I believe that my instantiation, of HX711 in ScaleMeasure.h HX711 _scale = HX711(_dout_pin, _clk_pin);
is not correct, or not in the right place. The code compile fine, though.
Thanks for your help.