#include "HX711.h"
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define CLK 13 // clock pin
#define DOUT1 5 // data pin to 1 HX711
#define DOUT2 6 // data pin to 2 HX711
#define DOUT3 7 // data pin to 3 HX711
#define DOUT4 8 // data pin to 4 HX711
#define SCALE_FACTOR 420.0 // wokwi equates 1kg to 420 "units"
String delim=" ";
byte DOUTS[4] = {DOUT1, DOUT2, DOUT3, DOUT4};
constexpr int channelCount = 4;
HX711 scales[channelCount];
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);//col-row
lcd.print("HX711-Multi");
lcd.setCursor(2,1);
lcd.print("#vedroracers");
scales[0].begin(DOUTS[0], CLK);
scales[1].begin(DOUTS[1], CLK);
scales[2].begin(DOUTS[2], CLK);
scales[3].begin(DOUTS[3], CLK);
delay(2000);
lcd.clear();
lcd.print("taring");
scales[0].tare(5);
lcd.print(".");
scales[1].tare(5);
lcd.print(".");
scales[2].tare(5);
lcd.print(".");
scales[3].tare(5);
lcd.print("done");
delay(1000);
lcd.clear();
lcd.print(scales[0].get_offset());
lcd.print(delim);
lcd.print(scales[1].get_offset());
lcd.print(delim);
lcd.setCursor(0,1);
lcd.print(scales[2].get_offset());
lcd.print(delim);
lcd.print(scales[3].get_offset());
delay(3000);
scales[0].set_scale(SCALE_FACTOR);
scales[1].set_scale(SCALE_FACTOR);
scales[2].set_scale(SCALE_FACTOR);
scales[3].set_scale(SCALE_FACTOR);
lcd.clear();
}
void loop() {
lcd.print(scales[0].get_units(), 2);
lcd.print(delim);
lcd.print(scales[1].get_units(), 2);
lcd.print(delim);
lcd.setCursor(0,1);
lcd.print(scales[2].get_units(), 2);
lcd.print(delim);
lcd.print(scales[3].get_units(), 2);
lcd.home();
delay(500);
}