59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
#include "../include/Balance.h"
|
|
|
|
Balance::Balance(int doutPin, int sckPin, String fullVall):
|
|
Capteur("W", fullVall){
|
|
|
|
this->capteur = new HX711();
|
|
this->capteur->begin(doutPin, sckPin);
|
|
this->initialized = false;
|
|
this->capteur->set_scale();
|
|
this->capteur->tare();
|
|
this->initialVal = 0;
|
|
this->calibrationFact = 0;
|
|
this->initCalibration();
|
|
}
|
|
|
|
boolean Balance::initCalibration() {
|
|
|
|
this->capteur->set_scale();
|
|
this->capteur->tare();
|
|
this->initialVal = this->capteur->read_average(20);
|
|
return true;
|
|
}
|
|
|
|
boolean Balance::calibration(int poidsRef,int moyenne_calibration) {
|
|
|
|
int rawValref = 0; // Valeur brute de plexiglas et poids réf
|
|
int tempPoids = 0; // C'est la valeur du poids en grammes calculée grâce au facteur de calibration
|
|
|
|
rawValref = this->capteur->read_average(moyenne_calibration);
|
|
this->calibrationFact = (rawValref - this->initialVal) / poidsRef;
|
|
do {
|
|
this->capteur->set_scale(calibrationFact);
|
|
tempPoids = this->capteur->get_units(5);
|
|
if (tempPoids < poidsRef) {
|
|
calibrationFact -= 1;
|
|
} else if (tempPoids > poidsRef) {
|
|
calibrationFact += 1;
|
|
}
|
|
} while (tempPoids != poidsRef);
|
|
return initialized = true;
|
|
}
|
|
|
|
String Balance::read() {
|
|
int sortie = (int)this->capteur->get_units();
|
|
this->full = sortie > this->fullVall.toInt();
|
|
if (this->initialized == true) {
|
|
return String(sortie);
|
|
} else {
|
|
return "0";
|
|
}
|
|
}
|
|
|
|
bool Balance::tar(int val){
|
|
this->initialized = true;
|
|
this->calibrationFact = val;
|
|
this->capteur->set_scale(val);
|
|
return this->initialized;
|
|
}
|