Pues entonces no veo la necesidad de cambiar a una maquina de estados, tienes ya un programa bien codificado y que funciona bien, solo hay que añadirle lo del bucle for.
Creo que el bucle for que te propuse en el pst #14 funciona , solo que le faltaba la impresion en el sserial y LCD.
Prueba el siguiente codigo corregido segun te comente en el post #25, yo no tengo termo-par ni lcd-12c.
#include <max6675.h>
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20 , 4); // variantes .
// 0x27 0x3F , 0x20 , 0x38 , 16 , 2 20 , 4
const byte thermoDO = 6;
const byte thermoCS = 5;
const byte thermoCLK = 4;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int i = 0;
int boton = 10;
const byte vccPin = 3;
const byte gndPin = 2;
const byte gndPinf = 8;
const byte vccPinr = 9;
const byte relePinA = 12;
const byte relePinB = 13;
float temprelePinA;
float temprelePinB;
unsigned long instanteAnterior;
bool enfriando = false;
bool bucle = false;
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("D. Marmo Servicios"); // Mensaje a desplegar
lcd.setCursor(0, 2);
lcd.print(" Secadora Do 6 "); // Mensaje 2 a desplegar
delay(3000); // espera 3 segundos con el mensaje estatico
Serial.begin(9600);
pinMode(vccPin, OUTPUT);
digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT);
digitalWrite(gndPin, LOW);
pinMode(vccPinr, OUTPUT);
digitalWrite(vccPinr, HIGH);
pinMode(gndPinf, OUTPUT);
digitalWrite(gndPinf, LOW);
pinMode(relePinA, OUTPUT);
pinMode(relePinB, OUTPUT);
pinMode(boton, INPUT);
Serial.println("temperatura ");
delay(3000);
}
void loop() {
if (!bucle && thermocouple.readCelsius() > 39.00) { // en la subida se detecta 39 .Entramos en el for
for (int i = 0; i < 3; i++) {
digitalWrite(relePinA, HIGH); // apagamos la "calefaccion", empieza a bajar la temperatura
while ( thermocouple.readCelsius() > 34.00) {// esperamos hasta que T = 34
PRINT_LCD (" Ciclo - " + String(i) + " ↓ ");
Serial.print (" Ciclo - ");
Serial.print (i);
Serial.print (" ¡Bajando! T = ");
Serial.print( thermocouple.readCelsius());
Serial. println (" grados");
delay (1000);
PRINT_LCD (" Temperatura ");
delay (1000);
}
digitalWrite(relePinA, LOW); // encendemos la calefacción
while ( thermocouple.readCelsius() < 39.00) {// esperamos otra vez hasta llegar a los 39
PRINT_LCD (" Ciclo - " + String(i) + " ↑ ");
Serial.print (" Ciclo - ");
Serial.print (i);
Serial.print (" ¡Subiendo! T = ");
Serial.print( thermocouple.readCelsius());
Serial. println (" grados");
delay (1000);
PRINT_LCD (" Temperatura ");
delay (1000);
}
// se repite el ciclo i veces
}
bucle = true; // una vez finalizado el for bloqueamos futuras activaciones del for en la bajada final
}
// continua el programa subiendo hasta los 42 despues bajara hasta finalizar sin activar el for
if (millis() - instanteAnterior > 2500UL) {
instanteAnterior = millis();
temprelePinA = thermocouple.readCelsius();
Serial.println( thermocouple.readCelsius());
if (enfriando == false) {
PRINT_LCD (" Temperatura ↑ ");
}
else {
PRINT_LCD (" Temperatura ↓ ");
}
Serial.println();
if (temprelePinA > ((digitalRead(boton) == HIGH) ? 40.00 : 42.0)) {
digitalWrite(relePinA, HIGH);
enfriando = true;
}
if (enfriando) {
if ( temprelePinA < 29.00) {
digitalWrite(relePinB, HIGH);
}
}
}
}
// funcion Para imprimir en el LCD
// Se ha de llamar con el texto a representar en
// la primera linea de LCD con 16 caracteres
void PRINT_LCD (String linea) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(linea);
delay(500);
lcd.setCursor(4, 2);
lcd.print("C = " + String(temprelePinA));
lcd.print((char)223);
}
Saludos.