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

#include "HX711.h"

HX711 load;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

 float weight =0;

void setup() {
  Serial.begin(115200);
//  Serial.println("Initializing the scale");

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
 
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  // Display static text
  display.println("Hello, world!");
  display.println("Fab Academy 2025");

  load.begin(D8, D7);

  //load.set_scale(); //The default scale is 1
  // load.tare();  // Take 20 readings, the average is the tare weight.
  load.set_scale(420);

  delay (2000);
}

void loop() {

//  Serial.println(load.get_units(), 1);
//  delay(1000);

    weight = load.get_units();

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  display.println("Fab Academy 2025");
  // Display static text

  display.setCursor(0, 30);
  display.setTextSize(2);
  display.println(weight);

  display.display();
}
esp:D0
esp:D1
esp:D2
esp:D3
esp:D4
esp:D5
esp:D6
esp:D7
esp:D8
esp:D9
esp:D10
esp:3V3
esp:GND
esp:5V
cell1:VCC
cell1:DT
cell1:SCK
cell1:GND
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA