Chance value water level

how do i write a code so i can change y

#include "HX711.h"
#include <EEPROM.h>

const int LOADCELL_DOUT_PIN = 23;
const int LOADCELL_SCK_PIN = 22;

#define EEPROM_SIZE 32

float y = 100; // vyska 100 mm
float m;
float reading;
  
HX711 scale;
 
void setup() {
  Serial.begin(115200);
  EEPROM.begin(EEPROM_SIZE);
  
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  reading = scale.read();
  delay(1000);
  m = scale.read();
  
}

void loop() {

  if (scale.wait_ready_timeout(1000)) {
    reading = scale.read();
    Serial.print("HX711 reading: ");
    Serial.println(reading);
    Serial.print("hodnota m=y: ");
    Serial.println(m);
    // float m = xxx; známa hodnota při zname vyšce
    float y1 = (y/m);
    EEPROM.writeFloat (0,y1);
    EEPROM.commit();
    EEPROM.readFloat (0);    
    float y2 = (y1*reading);
    EEPROM.readFloat (1);
    EEPROM.commit();
    EEPROM.writeFloat (1,y2);
    Serial.print("hladina: ");
    Serial.println(y2);
    // primka
    float dy = (y2-y);
    float dx = (reading-m);
    float a = (dy/dx);
    float b = (y-(a*m));
    float p = (a*reading+b);
    EEPROM.writeFloat (3,p);
    EEPROM.commit();
    EEPROM.readFloat (3);
    Serial.print("primka: ");
    Serial.println(p);

  } else {
    Serial.println("HX711 not found.");
  }
  delay(1500);
  
}

You could change y where it is currently set to 10-. Change it to whatever you want.

But you probably mean to make it adjustable.

What input device do you want to use to make the adjustment?

a7

write the value to the terminal keyboard

void loop()
{
  if (Serial.available())
  {
    y = Serial.parseFloat();
    Serial.print("y set to ");
    Serial.println(y);
  }
.
.
.

WARNING: If you don't set Serial Monitor to "No line ending" you will get y=0.0 after each correct entry.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.