
#include "HX711.h"

const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;

HX711 scale;

long scale_factor = 0;
long no_weight = 0;

void tare() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000);
  Serial.println("Alle Gewichte entfernen...");
  
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  delay(4000);
  Serial.println("[Measureing]");

  Serial.print("Null-Gewicht: ");
  no_weight = scale.get_units(3);
  Serial.println(no_weight);
  
  delay(1000);
  Serial.println("100g Gewicht platzieren...");
  delay(4000);

  Serial.print("100g-Gewicht: ");
  scale_factor = scale.get_units(3);
  Serial.println(scale_factor);

  scale_factor = scale_factor / 100;
  Serial.print("Skalierungsfaktor: ");
  Serial.println(scale_factor);

  delay(2000);
}

int len = 0;
long sum = 0;

void tare_loop() {
  delay(2000);
  long val = scale.get_units(1);
  // (WEIGHT_VAL - NO_WEIGHT_VAL) / (100g_val /100) = Gewicht in Gramm
  Serial.println( ( val - no_weight ) / scale_factor );
}

