Muito obrigado pela ajuda, concertei os erros, e funcionou.
Perdao pelo envio repetido no forum estou a pouco tempo e ainda nao tinha lido as regras,
Poderia me tirar mais uma duvida?
Existe alguma logica para inverter o valor do millis? por exemplo, eu coloco 60 segundos, e ao inves dele contar 1, 2, 3, 4....60, ele contasse 60, 59, 58.....1.
Ja que nos fornos mostra o valor descrescendo e nao crescendo.
abaixo vou deixar meu codigo para voce olhar.
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "Adafruit_MAX31855.h"
//
#define MAXDO 5
#define MAXCS 6
#define MAXCLK 7
//
LiquidCrystal_I2C lcd(0x27,20,4);
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);
//
double Tc;
//double Tc_aux = Tc - 23.5;
int flag = 0; //acionamento de carga
//flag = 0 ligar carga
//flag = 0 desliga carga
typedef enum {
ESTADO = 1,
TEMPERATURA = 2,
TEMPO = 3,
MONITORAR = 4,
CONTROLE = 5} ESTADO_t;
int botaoe;
int botao_;
int botaom;
int estado = 1;
int temp1 = 300;
int temp3 = 300;
int temp2 = 700;
int setpoint = 160;
int tempm = 10;
int temp_ = 10;
int setpointmin = 160;
int setpointmax = 300;
int tempmin = 5; // 10 minutos
int settempo = 10;
int tempmax = 60;
int tempom = 5;
int tempo_ = 5;
int rele = 13;
int atraso;
boolean teste = LOW;
int tempo = settempo * 60;
unsigned long tempoAtual;
unsigned long lastDebounceTime = 0; // última vez que o botão foi pressionado
unsigned long debounceDelay = 550; // O intervalo, igual ao delay do código anterior
//unsigned long tempoAtual = millis();
void setup() {
pinMode(botaoe, INPUT);
pinMode(botao_, INPUT);
pinMode(botaom, INPUT);
pinMode(rele, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("ELETIVA 2024");
lcd.setCursor(5, 1);
lcd.print("3V1 ELE");
Serial.begin(9600);
Tc = thermocouple.readCelsius();
}
void loop() {
botaoe = digitalRead(8);
botao_ = digitalRead(9);
botaom = digitalRead(10);
switch (estado) {
case ESTADO: {
lcd.setCursor(2, 0);
lcd.print("ELETIVA 2024");
lcd.setCursor(5, 1);
lcd.print("3V1 ELE");
/*if(botaoe == 1) {
estado = TEMPERATURA;
lcd.clear();
delay(temp3);
}*/
if (botaoe == HIGH) {
if ((millis() - lastDebounceTime) > debounceDelay) {
lcd.clear();
estado = TEMPERATURA;
}lastDebounceTime = millis();
}
}
break;
case TEMPERATURA: {
if(botaom == 1) {
setpoint = setpoint + tempm;
delay(temp3);
}
if(botao_ == 1){
setpoint = setpoint - temp_;
delay(temp3);
}
if(setpoint <= setpointmin){
setpoint = setpointmin;
delay(temp3);
}
if(setpoint >= setpointmax){
setpoint = setpointmax;
delay(temp3);
}
lcd.setCursor(0, 0);
lcd.print("TEMPERATURA:");
lcd.print(setpoint);
/*if(botaoe == 1) {
estado = TEMPO;
delay(temp1);
lcd.clear();
}*/
if (botaoe == HIGH) {
if ((millis() - lastDebounceTime) > debounceDelay) {
lcd.clear();
estado = TEMPO;
}lastDebounceTime = millis();
}
}
break;
case TEMPO:{
if(botaom == 1){
settempo = settempo + tempom;
delay(temp3);
}
if(botao_ == 1){
settempo = settempo - tempo_;
delay(temp3);
}
if(settempo <= tempmin){
settempo = tempmin;
delay(temp3);
}
if(settempo >= tempmax){
settempo = tempmax;
delay(temp3);
}
lcd.setCursor(0, 0);
lcd.print("TEMPO:");
lcd.print(settempo);
if (botaoe == HIGH) {
if ((millis() - lastDebounceTime) > debounceDelay) {
lcd.clear();
estado = MONITORAR;
}lastDebounceTime = millis();
}
}
break;
case MONITORAR: {
Tc = thermocouple.readCelsius();
if (isnan(Tc)) {
Serial.println("Thermocouple fault(s) detected!");
uint8_t e = thermocouple.readError();
if (e & MAX31855_FAULT_OPEN) Serial.println("FAULT: Thermocouple is open - no connections.");
if (e & MAX31855_FAULT_SHORT_GND) Serial.println("FAULT: Thermocouple is short-circuited to GND.");
if (e & MAX31855_FAULT_SHORT_VCC) Serial.println("FAULT: Thermocouple is short-circuited to VCC.");
} else {
Serial.print("C = ");
//Serial.println(Tc_aux);
Serial.println(flag);
//Serial.println(Tc);
}
lcd.setCursor(0,0);
lcd.print("TEMPERATURA:");
lcd.print(Tc);
lcd.setCursor(0, 1);
lcd.print("TEMPO:");
lcd.print(tempoAtual);
if(Tc <= 26){
digitalWrite(rele, HIGH);
lcd.setCursor(14, 1);
lcd.print("L");
}
//if(Tc >= setpoint - 10){
if(Tc > 26 + 0.5){
digitalWrite(rele, LOW);
lcd.setCursor(14, 1);
lcd.print("D");
}
delay(temp1);
if (botaoe == HIGH) {
if ((millis() - lastDebounceTime) > debounceDelay) {
lcd.clear();
estado = CONTROLE;
}lastDebounceTime = millis();
}
break;
case CONTROLE: {
//lcd.setCursor(0, 0);
//lcd.print("FORNO DESLIGADO");
if (botaom ==1) {
teste = !teste;
delay(10); //inverte a flag. Se o fogão estiver ligado, desliga. Se estiver desligado, liga
}
if (teste == HIGH){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("FORNO LIGADO");
delay(temp1);
}
else if (teste == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("FORNO DESLIGADO");
delay(temp1);
}
if (botaoe == HIGH) {
if ((millis() - lastDebounceTime) > debounceDelay) {
lcd.clear();
estado = ESTADO;
}lastDebounceTime = millis();
}
}
break;
/*if(Tc_aux >= setpoint + 10) {
flag = 1; // se a temperatura for maior que o setpoint, o flag desliga
}
if(Tc_aux <= setpoint - 10) {
flag = 0; // se a temperatura for menor que o setpoint, o flag liga
}*/
/* if(Tc <= setpoint + 10){
if(Tc <= 26){
digitalWrite(rele, HIGH);
lcd.setCursor(14, 1);
lcd.print("L");
}
//if(Tc >= setpoint - 10){
if(Tc > 26){
digitalWrite(rele, LOW);
lcd.setCursor(14, 1);
lcd.print("D");
}*/
/* if(teste = !teste){
tempoAtual = millis();
atraso = tempoAtual + tempo;
if(tempoAtual < delay){
digitalWrite(rele, HIGH);
}*/
}
}
}