#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "HX711.h" // Include the HX711 library
// HX711 circuit wiring
const int dataPin = 26;
const int clockPin = 27;
HX711 scale;
//HX711_ADC LoadCell(26, 27); // dt pin, sck pin
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int ButtonTaree = 25;
int ButtonOneItems = 33;
//int ButtonAllItems = 12;
float gramvalue;
int status = false;
bool eventTrigger = false;
void setup()
{
Serial.begin(115200);
scale.begin(dataPin, clockPin);
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(2, 0); // set cursor to first row
lcd.print("SMART SHELF "); // print out to LCD
lcd.setCursor(0, 1); // set cursor to first row
lcd.print(" 40KG MAX LOAD "); // print out to LCD
delay(3000);
lcd.clear();
pinMode (ButtonOneItems, INPUT_PULLUP);
pinMode (ButtonTaree, INPUT_PULLUP);
//Serial.print("UNITS: ");
//Serial.println(scale.get_units(10));
//Serial.println("\nEmpty the scale, press a key to continue");
//while(!Serial.available());
//while(Serial.available()) Serial.read();
//scale.tare();
//Serial.print("UNITS: ");
//Serial.println(scale.get_units(10));
//Serial.println("\nPut 1000 gram in the scale, press a key to continue");
//while(!Serial.available());
//while(Serial.available()) Serial.read();
//scale.calibrate_scale(1000, 5);
//Serial.print("UNITS: ");
//Serial.println(scale.get_units(10));
//Serial.println("\nScale is calibrated, press a key to continue");
// Serial.println(scale.get_scale());
// Serial.println(scale.get_offset());
//while(!Serial.available());
//while(Serial.available()) Serial.read();
}
void loop()
{
lcd.setCursor(1, 0); // set cursor to first row
lcd.print("Insert 1 Item"); // print out to LCD
//scale.get_offset(); // retrieves data from the load cell
gramvalue = scale.get_scale(); // get output value
if (gramvalue < 0)
{
gramvalue = 0;
}
else
{
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print(" ");
}
lcd.setCursor(5, 1); // set cursor to second row
lcd.print(gramvalue, 1); // print out the retrieved value to the second row
lcd.print("g ");
if (gramvalue >= 40000)
{
gramvalue = 0;
lcd.setCursor(0, 0); // set cursor to first row
lcd.print(" Over Loaded ");
delay(200);
}
if (digitalRead (ButtonTaree) == LOW)
{
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(" Taring... ");
scale.get_offset();
lcd.setCursor(0, 1);
lcd.print(" ");
}
}