from machine import Pin
from time import sleep
from hx711 import HX711
hx = HX711(Pin(4), Pin(5))
def calibracao(peso_real):
hx.tare()
sleep(7)
valor_bruto= hx.get_weight()
escala= valor_bruto / peso_real
hx.set_scale(escala)
calibracao(30)
def Balança():
Peso= round(hx.get_weight(times=10), 2)
if abs(Peso) < 0.3:
Peso = 0
print(f"Peso estimado: {Peso:.2f} g")
while True:
Balança()
sleep(1)