#include "HX711.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define DOUT 3
#define CLK 2
HX711 scale(DOUT, CLK);

float weight;
float calibration_factor = 123456;

#define SCREEN_WIDTH  128
#define SCREEN_HEIGHT  64

#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);



void setup() {
  Serial.begin(9600);
  Serial.println("HX711 Calibration");

  scale.set_scale();
  scale.tare();

  long zero_factor = scale.read_average();
  Serial.println("Zero factor:");
  Serial.println(zero_factor);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3c)
  delay(2000);

  display.clearDisplay();
  display.setTextColor(WHITE);

  // pinMode(BUTTON_UP_PIN, INPUT_PULLUP); // up button
  // pinMode(BUTTON_SELECT_PIN, INPUT_PULLUP); // select button
  // pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP); // down button
  // pinMode(DEMO_PIN, INPUT_PULLUP);
}


void loop() {
  scale.set_scale(calibration_factor);
  Serial.println("Reading:");
  weight = scale.get_units(5);
  if (weight < 0) {
    weight = 0.00;
  }

  display.clearDisplay();
  display.setTextSize(3);
  display.setCursor(0, 0);
  display.print("Weight:");

  display.setTextSize(3);
  display.setCursor(0, 35);
  display.print(weight);

  display.setTextSize(3);
  display.setCursor(75, 35);
  display.print("Kg");
  display.display();
  delay(2000);


}