#include "HX711.h"
HX711 scale;
float calibration_factor = 4.2; // Adjust this based on your load cell
float units;
float ounces;
void setup() {
  Serial.begin(9600);
  scale.begin(6, 5);
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor (by 1)");
  Serial.println("Press - or z to decrease calibration factor (by 1)");
  scale.set_scale();
  scale.tare();  //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}
void loop() {
  scale.set_scale(calibration_factor); //Adjust to this calibration factor
  Serial.print("Reading: ");
  units = scale.get_units()*10;  // Get raw units, no comma conversion needed
  if (units < 0) {
    units = 0.0;
  }
  ounces = units * 0.035274;
  Serial.print(units, 2);  // Print units with 2 decimal places
  Serial.print(" grams, ");
  Serial.print(ounces, 2);  // Print ounces with 2 decimal places
  Serial.print(" ounces, calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();
  if (Serial.available()) {
    char temp = Serial.read();
    if (temp == '+' || temp == 'a') {
      calibration_factor += 0.01;  // Adjust by 1.0 for better control
    } else if (temp == '-' || temp == 'z') {
      calibration_factor -= 0.01;
    }
  }
}