#include <LiquidCrystal.h>
#include <HX711.h>

// Define the pins for the load cells and the HX711 amplifier modules
#define LOADCELL_1_DOUT_PIN  3
#define LOADCELL_1_SCK_PIN  2
#define LOADCELL_2_DOUT_PIN  5
#define LOADCELL_2_SCK_PIN  4
#define LOADCELL_3_DOUT_PIN  7
#define LOADCELL_3_SCK_PIN  6
#define LOADCELL_4_DOUT_PIN  9
#define LOADCELL_4_SCK_PIN  8
#define LOADCELL_5_DOUT_PIN  11
#define LOADCELL_5_SCK_PIN  10

// Define the pins for the LCD screen
#define LCD_RS_PIN  13
#define LCD_EN_PIN  12
#define LCD_D4_PIN  11
#define LCD_D5_PIN  10
#define LCD_D6_PIN  9
#define LCD_D7_PIN  8

// Define the calibration factors for the load cells
float calibration_factor_1 = 1.0;
float calibration_factor_2 = 1.0;
float calibration_factor_3 = 1.0;
float calibration_factor_4 = 1.0;
float calibration_factor_5 = 1.0;

// Initialize the LCD screen
LiquidCrystal lcd(LCD_RS_PIN, LCD_EN_PIN, LCD_D4_PIN, LCD_D5_PIN, LCD_D6_PIN, LCD_D7_PIN);

// Initialize the HX711 libraries
HX711 scale_1;
HX711 scale_2;
HX711 scale_3;
HX711 scale_4;
HX711 scale_5;

void setup() {
  // Set up the LCD screen
  lcd.begin(16, 2);
  lcd.print("Weight 1: ");
  lcd.setCursor(0, 1);
  lcd.print("Weight 2: ");
  lcd.setCursor(0, 2);
  lcd.print("Weight 3: ");
  lcd.setCursor(0, 3);
  lcd.print("Weight 4: ");
  lcd.setCursor(0, 4);
  lcd.print("Weight 5: ");
  
  // Set up the HX711 amplifier modules
  scale_1.begin(LOADCELL_1_DOUT_PIN, LOADCELL_1_SCK_PIN);
  scale_1.set_scale(calibration_factor_1);
  scale_1.tare();
  scale_2.begin(LOADCELL_2_DOUT_PIN, LOADCELL_2_SCK_PIN);
  scale_2.set_scale(calibration_factor_2);
  scale_2.tare();
  scale_3.begin(LOADCELL_3_DOUT_PIN, LOADCELL_3_SCK_PIN);
  scale_3.set_scale(calibration_factor_3);
  scale_3.tare();
  scale_4.begin(LOADCELL_4_DOUT_PIN, LOADCELL_4_SCK_PIN);
  scale_4.set_scale(calibration_factor_4);
  scale_4.tare();
  scale_5.begin(LOADCELL_5_DOUT_PIN, LOADCELL_5_SCK_PIN);
  scale_5.set_scale(calibration_factor_5);
  scale_5.tare();
}

void loop() {
  // Read the weight from each load cell
  float weight_1 = scale_1.get_units();
  float weight_2 = scale_2.get_units();
  float weight_3 = scale_3.get_units();
  float weight_4 = scale_4.get_units();
  float weight_5 = scale_5.get_units();

  // Display the weight of each load cell on the LCD screen
  lcd.setCursor(10, 0);
  lcd.print(weight_1, 2);
  lcd.print(" g");
  lcd.setCursor(10, 1);
  lcd.print(weight_2, 2);
  lcd.print(" g");
  lcd.setCursor(10, 2);
  lcd.print(weight_3, 2);
  lcd.print(" g");
  lcd.setCursor(10, 3);
  lcd.print(weight_4, 2);
  lcd.print(" g");
  lcd.setCursor(10, 4);
  lcd.print(weight_5, 2);
  lcd.print(" g");

  // Wait for a short time before reading again
  delay(100);
}