Automatic mixing valve

Good evening everyone, I have a problem, I need help to correct the program I made, I have two problems left that I can't solve, the first is that every now and then I see the old temperature, the second is that I need to stabilize better the temperature.
Please can you help me?

void loop()
{

int blocca = digitalRead(finecorsa);
int blocca1 = digitalRead(finecorsa1);
int blocca2 = digitalRead(finecorsa2);
  

  sensore.requestTemperatures();  // richiesta lettura temperatura
  float celsius = sensore.getTempCByIndex(0);
  celsius = int(celsius * 10) / 10;


  { 
     if ((celsius-temp) > (2))  
 {
v1 = ((celsius- temp));
}
else 
v1 = ((celsius-temp)/6);


if ((temp-celsius) == (1) or (celsius-temp) == (1))  
v1 = ((celsius-temp)/5);

 //fa entrare l'acqua fredda
  if (temp < (celsius) && (digitalRead(15) == HIGH))
   {
      sensore.requestTemperatures();
      celsius = sensore.getTempCByIndex(0);
 digitalWrite(pinEnable, enable);
      stepper1.move(1); // 200/second = 1 rps
   stepper1.currentPosition() != 0;
      stepper1.setSpeed(v1);
    stepper1.runSpeed();
Serial.println(v1);
TFTlcd.SetNumberValue(1, 13, celsius);
        }

 if ((temp-celsius) > (2))  
 {
v1 = ((temp-celsius));
}
else 
v1 = ((temp-celsius)/6);

if ((temp-celsius) == (1) or (celsius-temp) == (1))  
v1 = ((temp-celsius)/5);

   //fa entrare l'acqua calda
   if (temp > (celsius) && (digitalRead(14) == HIGH))
{
    sensore.requestTemperatures();
    celsius = sensore.getTempCByIndex(0);
 digitalWrite(pinEnable, enable);
    stepper1.move(-1); // 200/second = 1 rps
    stepper1.currentPosition() != -0;
      stepper1.setSpeed(-v1);
    stepper1.runSpeed();
Serial.println(-v1);
TFTlcd.SetNumberValue(1, 13, celsius);
  }
  }

if (temp == celsius)
digitalWrite(pinEnable, !enable);
//Serial.println(-v1);
TFTlcd.SetNumberValue(1, 13, celsius);

I can't just now from under the umbrella.

When I look next, I hope to see that you have posted a complete sketch that compiles and we can run.

It really is best - it is unnatural to work with fragments of code. You did not even post a complete loop() function.

Please use the Auto Format tool on the IDE before you post the sketch. It will put you code in a standard format, which will also make it easier to read, understand and fix.

TIA

a7

@aladillo this is not a code

Hello aladillo

The sketch won´t compile.

It's just part of the code

sorry, but it is not a code, it is a mess

Please do auto-format (Ctrl-T) in the IDE window before inserting the code to the forum.
It's also a good rule of thumb to show complete code that each responder can copy into their IDE and compile.
If your code is too large or contains parts that are not relevant to the question, then it would be good to prepare a separate example for the forum that demonstrates the problem

confusing
can you explain what your code is attempting to do?

it looks like a block of code is duplicated: one doing celsius - temp, the other temp-clesius. have you considered abs(temp-celsius).

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