#include <HX711.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
#define DATA_PIN 19
#define CLOCK_PIN 18
#define led 5
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
HX711 hx711;
volatile float units;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
hx711.begin(DATA_PIN, CLOCK_PIN);
lcd.init();
lcd.backlight();
pinMode(led, OUTPUT);
// Efetua a leitura e calcula a escala
// long average = hx711.read_average(50);
// float scale = ((average - hx711.get_offset()) / 1.00f);
// Define com a escala calculada
hx711.set_scale(420.0983);
hx711.tare();
}
void loop() {
units = hx711.get_units();
Serial.println(units);
lcd.setCursor(2, 0);
lcd.print("Berat :");
lcd.print(units);
if(units < 4.9){
digitalWrite(led, HIGH);
}
else{
digitalWrite(led, LOW);
}
delay(1000);
}