Il drop my code here for anyone who has any idea on how can i code two buttons into my webPage, but please dont change any of the code just show me how to create and how to use it and how t o gatter the input received from him (parts of the code are poorly documented, and most of the variables are not actually being used as i forgot to delet them).
#include <WiFi.h>
#include <HX711.h>
#define DOUT 2 // Data do HX711
#define CLK 5 // Clock do HX711
#define butto 0
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
HX711 balanca;
float peso, raw;
float fator_calibracao = 1100.0;
WiFiServer server(80);
float rawCalibrado = 0;
int buttonState = 0, x = 0; // variable for reading the pushbutton status
float minRaw, maxRaw, midRaw = 0;
uint32_t weight;
bool buclemyshoe = false;
void setup() {
Serial.begin(115200);
pinMode(butto, INPUT);
Serial.print("Setting AP (Access Point)…");
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
delay(500);
Serial.println("Inicializando balança...");
balanca.begin(DOUT, CLK);
balanca.set_scale(fator_calibracao);
balanca.tare();
Serial.println("Balança pronta para pesar.");
server.begin();
}
void loop() {
buttonState = digitalRead(butto);
peso = balanca.get_units(5);
raw = balanca.read();
rawCalibrado = ((raw - minRaw) * weight) / midRaw;
WiFiClient client = server.available();
if (client) {
Serial.println("New Client.");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
currentLine += c;
if (c == '\n') {
if (currentLine.length() == 2) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
client.println("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta http-equiv='refresh' content='1'></head>");
client.println("<body><h1>Peso Atual</h1><br>");
client.println("<br>Peso: " + String(peso) + "</body></html>");
client.println("<br>Peso: " + String(raw) + "</body></html>");
client.println("<br>Peso: " + String(rawCalibrado) + "</body></html>");
client.println("<p>Durante a calibração utilize o serial monitor</p>");
if (buttonState == LOW)
{
rawcalibr();
client.println();
break;
}
else {
client.println();
break;
}
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
}
}
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
void rawcalibr()
{
Serial.println("\n\nCALIBRATION\n===========");
Serial.println("remove all weight from the loadcell");
// flush Serial input
while (Serial.available()) Serial.read();
Serial.println("and press enter\n");
while (Serial.available() == 0);
Serial.println("Determine zero weight offset");
//minRaw = 0;
//x = 0;
//for (int i = 0; i < 10; i++)
//{
// x = balanca.read();
// minRaw = minRaw + x;
//}
//minRaw = minRaw/10;
minRaw = balanca.read();
Serial.print("Minium Raw Value: ");
Serial.println(minRaw);
Serial.println();
Serial.println("place a weight on the loadcell");
// flush Serial input
while (Serial.available()) Serial.read();
Serial.println("enter the weight in (whole) grams and press enter");
weight = 0;
while (Serial.peek() != '\n')
{
if (Serial.available())
{
char ch = Serial.read();
if (isdigit(ch))
{
weight *= 10;
weight = weight + (ch - '0');
}
}
}
Serial.print("Current Weight: ");
Serial.println(weight);
//maxRaw = 0;
//x = 0;
//for (int i = 0; i < 10; i++)
//{
// x = balanca.read();
// maxRaw = maxRaw + x;
//}
//maxRaw = maxRaw/10;
maxRaw = balanca.read();
midRaw = maxRaw-minRaw;
Serial.println(weight);
Serial.println(minRaw);
Serial.println(maxRaw);
}