#include "HX711.h"
#include "SevSeg.h"

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define LOADCELL_DOUT_PIN  A3
#define LOADCELL_SCK_PIN  A4

HX711 scale;
SevSeg mysevi; 

void displayWeight(float lw)
{
  mysevi.setNumber((lw*100), 2);
  mysevi.refreshDisplay();
}

void setup()
{
  byte numDigits = 4;
  byte digitPins[] = {2, 3, 4, 5};
  byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
  bool resistorsOnSegments = true; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_ANODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected

  mysevi.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
  mysevi.setBrightness(90);

  Serial.begin(9600);
  
  Serial.println("Scale Reading:");

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");

}

float scaleValue = 12.23 ; // ( scale.get_units() / 0.45359237 ) ; // convert from lbs to kg */
float scale2Value;

void loop() {
  
  if (scale.is_ready()) {
    scale2Value =  scale.get_units();
    Serial.print("scaleValue: ");
    Serial.print(scaleValue, 2);
    Serial.print(" kg");
    Serial.print(" | scale2Value: ");
    Serial.print(scale2Value);
    Serial.println();
  }
  displayWeight(scale2Value);
}