#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() { if (this->initialized == true) { return String(this->capteur->get_units()); } else { return "0"; } } void Balance::setCalibrationFact(int caliFact){ this->initialized = true; this->calibrationFact = caliFact; this->capteur->set_scale(caliFact); }