#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "HX711.h"
// Pins pour les capteurs de pesage
const int LOADCELL_DOUT_PIN = 16; // Broche DOUT du premier capteur
const int LOADCELL_SCK_PIN = 4; // Broche SCK du premier capteur
// Pins pour les boutons
const int POWER_BUTTON = 13;
// Facteur de calibration initial
const float DEFAULT_CALIBRATION_FACTOR = 420.0983;
// Adresse de l'écran LCD I2C
const int LCD_ADDRESS = 0x27;
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLS, LCD_ROWS);
HX711 scale; // Création de l'objet HX711
void setup() {
Serial.begin(9600);
//initialisation du capteur de poids
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
//initialisation POWER_BUTTON
pinMode(POWER_BUTTON, INPUT_PULLUP);
//initialisation LCD
lcd.init();
lcd.backlight();
}
void loop() {
// Tare la balance si le bouton est enfoncé
lcd.clear();
lcd.print("Tare en cours...");
scale.tare();
lcd.setCursor(0, 1);
lcd.print("Balance a zero");
delay(2000);
lcd.clear();
// Réglez l'échelle avec le facteur de calibration
scale.set_scale(DEFAULT_CALIBRATION_FACTOR);
// Affichez le facteur de calibration
lcd.clear();
lcd.print("Facteur calib:");
lcd.setCursor(0, 1);
lcd.print(DEFAULT_CALIBRATION_FACTOR);
delay(3000);
// Mesurez et affichez le poids actuel
lcd.clear();
lcd.print("Poids actuel:");
lcd.setCursor(0, 1);
lcd.print(scale.get_units(10)); // Lecture avec moyenne de 10 lectures
lcd.print(" g");
delay(3000);
lcd.clear();
}