#include <HX711.h>

#define DOUT1  14 // pin DOUT HX711
#define CLK1   13  // pin CLK HX711

#define DOUT2  27
#define CLK2   26

#define DOUT3  25
#define CLK3   33

#define DOUT4  32
#define CLK4   35

#define BUTTON_TERA   18

String myString; 
String cmessage; // complete message
char buff[10];
float weight; 
float calibration_factor = 206140; // for me this vlaue works just perfect 206140
HX711 scale;   // inisialisasi objek scale dengan pin DOUT dan CLK

void setup() {
  Serial.begin(9600);     // inisialisasi komunikasi serial
   
  pinMode(BUTTON_TERA, INPUT_PULLUP); 
  scale.begin(DOUT1,CLK1); 
  scale.set_scale();
    Serial.println("Baca Berat");
 
  scale.tare(); //Reset the scale to 0
  //long zero_factor = scale.read_average(); //Get a baseline reading
  //Serial.println("Baca Berat2");
}

void loop() {
 
scale.set_scale(calibration_factor); //Adjust to this calibration factor

weight = scale.get_units(50); //5
myString = dtostrf(weight, 3, 3, buff);
cmessage = cmessage + "Weight" + ":" + myString + "Kg"+","; 
Serial.println(cmessage); 
cmessage = "";

  Serial.println();

  if ( digitalRead(BUTTON_TERA) == LOW)
  {
    Serial.println("tare");
     scale.set_scale();
  scale.tare(); //Reset the scale to 0
  }
  delay(100);
  
}