31 lines
620 B
C++
31 lines
620 B
C++
#include "HX711.h"
|
|
#include <cstdint>
|
|
|
|
|
|
template<int DIVIDER=128>
|
|
class Scale
|
|
{
|
|
public:
|
|
bool measure(uint16_t & measurementOut) {
|
|
if (hx711_.is_ready())
|
|
{
|
|
uint32_t value = hx711_.get_value(MEASUREMENT_AVG_COUNT);
|
|
measurementOut = (int16_t)(value / DIVIDER);
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
|
|
void begin(uint32_t pinDOUT, uint32_t pinSCK) {
|
|
hx711_.begin(pinDOUT, pinSCK);
|
|
};
|
|
|
|
void tare(uint32_t numMeasurementsToAverage=50) {
|
|
hx711_.tare(numMeasurementsToAverage);
|
|
}
|
|
|
|
private:
|
|
HX711 hx711_;
|
|
};
|