/**************************************************************************************************************
** Programa para Análise de Corrente de entrada: ****
** Atualização da placa controladora genérica, instalado biblioteca ACS712 para fazer leitura da ****
** corrente RMS mais precisa. Outra atualização é o uso da análise da carga inicial, caso o consumo seja ****
** igual ou superior a 9A o programa entra no laço de ligar cada saída sequêncialmente, o programa ****
** verifica a cada etapa se é possível manter mais de uma saída ligada simultaneamente sem que ultra ****
** passe um consumo superior a 10A. ****
** Enquanto o consumo for maior do que 10A para todas as entradas ligadas o Charge Mate fica ****
** aternando qual saída fica ligada. ****
** Desenvolvimento\Modificação feita por Fernando Macedo Mano ****
**************************************************************************************************************/
#include "ACS712.h"
#include <Adafruit_GFX.h> // Biblioteca de gráficos
#include <Adafruit_ST7735.h> // Biblioteca do hardware ST7735
#include <SPI.h> // Biblioteca para comunicação SPI
#include <Fonts/FreeSans9pt7b.h>
// Pinos do display
// Configuração do PCB EasyEDA
#define TFT_DC 12 // A0
#define TFT_CS 13 // CS
#define TFT_MOSI 14 // SDA
#define TFT_CLK 27 // SCK
#define TFT_RST 0 // RESET
#define TFT_MISO 0 // MISO
// Instância do objeto tipo Adafruit_ST7735 que recebe como argumentos os pinos de controle
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);
ACS712 sensor(ACS712_20A, 04);
hw_timer_t *timer = NULL; //faz o controle do temporizador (interrupção por tempo)
//função que o temporizador irá chamar, para reiniciar o ESP32
void IRAM_ATTR resetModule(){
ets_printf("(watchdog) reiniciar\n"); //imprime no log
esp_restart(); //reinicia o chip
}
// Parâmetros Globais
const int RELAY1 = 19; //Saida 1 por relay
const int RELAY2 = 18; //Saida 2 por relay
const int RELAY3 = 05 ; //Saida 3 por relay
const int RELAY4 = 17; //Saida 4 por relay
const int SENSOR = 04; //Entrada do sensor de corrente
const int Tensao = 15; //Entrada do sensor de tensão
float Consumo_Inicial = 0;
unsigned long Tempo_inicial,Tempo_final,Tempo_escritaf,Tempo_escritai;
int Estado_Maquina = 0, Maquina_Estado = 0;
int ValTensao;
float tensao = 110, corrente = 0;
const unsigned char epd_bitmap_Bitmap [] PROGMEM = {
// 'movplogosem, 168x128px
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x03, 0xff, 0xdf, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x03, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x07, 0xff, 0x00, 0x3f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
0xff, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0xff, 0xff,
0xff, 0xfe, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xfc, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x07, 0xff, 0x80, 0x03, 0xff, 0xc0, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x1f, 0xfc, 0x00, 0x00,
0x7f, 0xf0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xe0, 0x3f, 0xe0, 0x00, 0x00, 0x0f, 0xf8, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x7f, 0x80, 0x00, 0x00, 0x03, 0xfc, 0x07, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0x00, 0x00, 0x00, 0x01,
0xfe, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81,
0xfc, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x81, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfc, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x1f, 0x81, 0x80,
0x00, 0x00, 0x03, 0x03, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xf8, 0x3f, 0x01, 0xc0, 0x00, 0x00, 0x07, 0x01, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3e, 0x01, 0xe0, 0x00, 0x00, 0x0f, 0x00, 0xf8, 0x1f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7e, 0x01, 0xf0, 0x00,
0x00, 0x1f, 0x00, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xf0, 0x7c, 0x01, 0xfc, 0x00, 0x00, 0x7f, 0x00, 0x7c, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xfc, 0x01, 0xfe, 0x00, 0x00, 0xff, 0x00, 0x7e, 0x0f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xf8, 0x01, 0xff, 0x00, 0x01,
0xff, 0x00, 0x7e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0,
0xf8, 0x01, 0xff, 0x80, 0x03, 0xff, 0x00, 0x3e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xf8, 0x01, 0xff, 0xe0, 0x0f, 0xff, 0x00, 0x3e, 0x07, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0xf0, 0x1f, 0xff,
0x00, 0x3f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0,
0x01, 0xff, 0xf8, 0x3f, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0xfc, 0x7f, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00,
0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01,
0xff, 0xff, 0xff, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1f,
0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff,
0xff, 0xff, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xc1, 0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0xbf, 0xfb, 0xff, 0x00, 0x1f, 0x07,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0x9f,
0xf3, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xc1, 0xf0, 0x01, 0xff, 0x87, 0xe3, 0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0x83, 0x83, 0xff, 0x00, 0x1f, 0x07, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xf0, 0x01, 0xff, 0x81, 0x03,
0xff, 0x00, 0x1f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1,
0xf0, 0x01, 0xff, 0x80, 0x03, 0xff, 0x00, 0x3f, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xf8, 0x01, 0xff, 0x80, 0x03, 0xff, 0x00, 0x3e, 0x07, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xf8, 0x01, 0xff, 0x80, 0x03, 0xff,
0x00, 0x3e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xf8,
0x01, 0xff, 0x80, 0x03, 0xff, 0x00, 0x3e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe1, 0xfc, 0x00, 0xff, 0x80, 0x03, 0xfe, 0x00, 0x7e, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x7f, 0x80, 0x03, 0xfc, 0x00,
0x7c, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00,
0x3f, 0x80, 0x03, 0xf8, 0x00, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f, 0x80, 0x03, 0xf0, 0x00, 0xf8, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01, 0xf8,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x03,
0x80, 0x03, 0x80, 0x03, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x80, 0x01, 0x80, 0x03, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x80, 0x02, 0x00, 0x07, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xc7, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0xff, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x7f, 0x80, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x3f, 0xe0, 0x00, 0x00, 0x0f,
0xf8, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x1f, 0xf8, 0x00, 0x00, 0x3f, 0xf0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x07, 0xff, 0x00, 0x01, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0xff, 0xfe, 0xff, 0xff, 0x80,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00,
0xff, 0xff, 0xff, 0xfe, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xe0, 0x03, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
0xff, 0xff, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xe3, 0xe0, 0x78, 0xff, 0x30, 0x07, 0xe3, 0xff,
0xe0, 0x3c, 0x7f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xc3, 0x80, 0x18,
0xfe, 0x20, 0x01, 0xc3, 0xff, 0x80, 0x0c, 0x7f, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0x1f, 0xc7, 0x1f, 0x8c, 0x7e, 0x31, 0xf8, 0xe3, 0xff, 0x1f, 0x8c, 0x3f, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xc7, 0x3f, 0xcc, 0x7e, 0x71, 0xfc, 0x63, 0xff, 0x1f,
0xc4, 0x3f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0x87, 0x3f, 0xcc, 0x7e,
0x71, 0xfc, 0x63, 0xff, 0x1f, 0xc4, 0x1f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0x0f, 0x87, 0x3f, 0xce, 0x7c, 0x71, 0xfc, 0x63, 0xff, 0x1f, 0xc4, 0x1f, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x0f, 0x07, 0x3f, 0xce, 0x3c, 0x71, 0xfc, 0x63, 0xff, 0x1f, 0xc4,
0x0f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0x27, 0x3f, 0xce, 0x3c, 0xf1,
0xfc, 0x63, 0xff, 0x1f, 0xc4, 0x4f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x27,
0x27, 0x3f, 0xce, 0x38, 0xf1, 0xfc, 0x63, 0xff, 0x1f, 0xc4, 0x47, 0x3f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x26, 0x67, 0x3f, 0xcf, 0x38, 0xf1, 0xfc, 0x63, 0xff, 0x1f, 0xc4, 0x67,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x32, 0x67, 0x3f, 0xcf, 0x18, 0xf1, 0xfc,
0x63, 0xff, 0x00, 0x04, 0x63, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x30, 0xe7,
0x3f, 0xcf, 0x19, 0xf1, 0xfc, 0x63, 0xff, 0x1f, 0xc4, 0x73, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0x30, 0xe7, 0x3f, 0xcf, 0x91, 0xf1, 0xf0, 0xe3, 0xff, 0x3f, 0xc4, 0x73, 0x3f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x38, 0xe7, 0x3f, 0xcf, 0x91, 0xf0, 0x03, 0xe3,
0xff, 0x1f, 0xc4, 0x78, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x39, 0xe7, 0x3f,
0xcf, 0x83, 0xf1, 0xff, 0xe3, 0xff, 0x1f, 0xc4, 0x78, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xfe, 0x3d, 0xe7, 0x3f, 0xcf, 0x83, 0xf1, 0xff, 0xe3, 0xff, 0x1f, 0xc4, 0x7c, 0x3f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xe7, 0x1f, 0x8f, 0xc3, 0xf1, 0xff, 0xe3, 0xff,
0x1f, 0xc4, 0x7c, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xe7, 0x1f, 0x8f,
0xc3, 0xf1, 0xff, 0xf1, 0xff, 0x1f, 0xc4, 0x7e, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfe, 0x3f, 0xe3, 0x80, 0x1f, 0xc7, 0xf1, 0xff, 0xf8, 0x02, 0x1f, 0xc4, 0x7e, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
/******************************************
** Função análise de Carga:
**Verifica qual é o consumo de cada saída
**individualmente
******************************************/
void Analise_Consumo () {
Consumo_Inicial = 0;
float valorCorrente_AUX = 0;
Desliga_rele();
digitalWrite(RELAY1, HIGH);
delay(10000);
valorCorrente_AUX = sensor.getCurrentAC(60);
Consumo_Inicial += valorCorrente_AUX;
digitalWrite(RELAY1, LOW);
delay(100);
digitalWrite(RELAY2, HIGH);
delay(10000);
valorCorrente_AUX = sensor.getCurrentAC(60); //O número 60 é referente a 60 Hz
Consumo_Inicial += valorCorrente_AUX;
digitalWrite(RELAY2, LOW);
delay(100);
digitalWrite(RELAY3, HIGH);
delay(10000);
valorCorrente_AUX = sensor.getCurrentAC(60);
Consumo_Inicial += valorCorrente_AUX;
digitalWrite(RELAY3, LOW);
delay(100);
digitalWrite(RELAY4, HIGH);
delay(10000);
valorCorrente_AUX = sensor.getCurrentAC(60);
Consumo_Inicial += valorCorrente_AUX;
Rele4ON();
//digitalWrite(RELAY4, LOW);
}
/* **************************************
** Funçao de ligar Reles:
** Como cada rele pode ter alguma carga
** atrelada a ele é ligado gradativamente
** para não sobrecarregar a rede elétrica
****************************************/
void Liga_rele () {
digitalWrite(RELAY1, HIGH);
Rele1ON();
delay(20000);
digitalWrite(RELAY2, HIGH);
Rele2ON();
delay(20000);
digitalWrite(RELAY3, HIGH);
Rele3ON();
delay(300);
Rele4ON();
//digitalWrite(RELAY4, HIGH);
}
void Rele1ON () {
tft.fillRect(42, 99, 28, 28, ST77XX_GREEN);
tft.setCursor(48,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("ON");
tft.setCursor(53,102);
tft.print("1");
}
void Rele1OFF () {
tft.fillRect(42, 99, 28, 28, ST77XX_RED);
tft.setCursor(48,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("OFF");
tft.setCursor(53,102);
tft.print("1");
}
void Rele2ON () {
tft.fillRect(72, 99, 28, 28, ST77XX_GREEN);
tft.setCursor(79,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("ON");
tft.setCursor(83,102);
tft.print("2");
}
void Rele2OFF () {
tft.fillRect(72, 99, 28, 28, ST77XX_RED);
tft.setCursor(78,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("OFF");
tft.setCursor(83,102);
tft.print("2");
}
void Rele3ON () {
tft.fillRect(102, 99, 28, 28, ST77XX_GREEN);
tft.setCursor(110,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("ON");
tft.setCursor(116,102);
tft.print("3");
}
void Rele3OFF () {
tft.fillRect(102, 99, 28, 28, ST77XX_RED);
tft.setCursor(109,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("OFF");
tft.setCursor(115,102);
tft.print("3");
}
void Rele4ON () {
tft.fillRect(132, 99, 27, 28, ST77XX_GREEN);
tft.setCursor(139,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("ON");
tft.setCursor(145,102);
tft.print("4");
}
void Rele4OFF () {
tft.fillRect(132, 99, 27, 28, ST77XX_RED);
tft.setCursor(138,115);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLACK);
tft.print("OFF");
tft.setCursor(145,102);
tft.print("4");
}
/* *********************************************
** Funçao de Desligar Reles:
** Como é apenas desligar todos
** as saídas não precisa de intervalo
** entre o acionamento de cada rele
***********************************************/
void Desliga_rele () {
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, LOW);
delay(50);
}
void Masca_Medidor () {
tft.setTextSize(3); // Seta o tamanho da fonte de texto para o tamanho 2
tft.setCursor(40,3); // Move o cursor para a coluna 30 na linha 0
tft.fillScreen(ST7735_BLACK); // Preenche a tela com a cor preta
tft.fillRoundRect(00, 00, 180, 23, 0, ST77XX_BLUE);
tft.setTextColor(ST7735_WHITE); // Seta a cor do texto para Azul
tft.print("VOLTS"); // Escreve a palavra Vida Com a cor que foi setada na linha acima
tft.setTextSize(2); // Seta o tamanho da fonte de texto para o tamanho 2
tft.setCursor(50,30); // Move o cursor para a coluna 30 na linha 0
tft.print(tensao);
tft.print(" V");
tft.setCursor(5,50); // Move o cursor para a coluna 30 na linha 0
tft.setTextSize(3); // Seta o tamanho da fonte de texto para o tamanho 2
tft.fillRoundRect(00, 48, 180, 23, 0, ST77XX_BLUE);
tft.setTextColor(ST7735_WHITE); // Seta a cor do texto para Azul
tft.print("CORRENTE"); // Escreve a palavra Vida Com a cor que foi setada na linha acima
tft.setTextSize(2); // Seta o tamanho da fonte de texto para o tamanho 2
tft.setCursor(50,78);
tft.print(corrente);
tft.print(" A");
tft.fillRoundRect(00, 98, 40, 35, 0, ST77XX_BLUE);
tft.setTextSize(1); // Seta o tamanho da fonte de texto para o tamanho 2
tft.setCursor(2,110);
tft.print("Saidas");
tft.drawRect(41, 98, 30, 30, ST77XX_WHITE);
Rele1OFF();
tft.drawRect(71, 98, 30, 30, ST77XX_WHITE);
Rele2OFF();
tft.drawRect(101, 98, 30, 30, ST77XX_WHITE);
Rele3OFF();
tft.drawRect(131, 98, 29, 30, ST77XX_WHITE);
Rele4OFF();
}
/****************************************************************
* Função de configuração dos Pinos do Arduino
* Pinos de Saída, o pino de leitura do sensor
* de corrente e os pinos usados pelo LCD
* **********************************************************/
void setup() {
Desliga_rele();
tft.initR(INITR_BLACKTAB); // Inicializa a tela com um fundo preto
tft.setRotation(1); //Ajusta a rotação do display
//Abertura_Disp();
tft.fillScreen(ST7735_BLUE); // Preenche a tela com a cor preta
tft.drawBitmap(0,0, epd_bitmap_Bitmap, 168, 128, ST77XX_WHITE);
tft.setCursor (20, 115);
tft.setTextColor(ST7735_BLUE);
tft.print("Solucoes Educacionais");
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
pinMode(SENSOR, INPUT);
pinMode(Tensao, INPUT);
//Inicia os estados dos pinos de saída dos relés como desligado
//Inicia a comunicação seria
Serial.begin(9600);
Serial.println("Calibrando sensor de corrente, certifique que não haja consumo de corrente neste momento");
sensor.calibrate();
Serial.println("Sensor Calibrado!");
//Masca_Medidor ();
Analise_Consumo ();
Masca_Medidor ();
tft.fillRoundRect(00, 71, 180, 23, 0, ST77XX_BLACK);
tft.setCursor(50,78);
corrente = Consumo_Inicial;
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(2);
tft.print(corrente);
tft.print(" A");
Rele4ON();
if (Consumo_Inicial <= 29.21) {
Liga_rele();
Maquina_Estado = 0x33;
}
if (Consumo_Inicial > 29.21) {
Maquina_Estado = 0xFF;
Desliga_rele();
digitalWrite(RELAY1, HIGH);
Estado_Maquina = 2;
}
Tempo_inicial = millis();
Tempo_escritai = millis();
//hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp)
/*
num: é a ordem do temporizador. Podemos ter quatro temporizadores, então a ordem pode ser [0,1,2,3].
divider: É um prescaler (reduz a frequencia por fator). Para fazer um agendador de um segundo,
usaremos o divider como 80 (clock principal do ESP32 é 80MHz). Cada instante será T = 1/(80) = 1us
countUp: True o contador será progressivo
*/
timer = timerBegin(0, 80, true); //timerID 0, div 80
//timer, callback, interrupção de borda
timerAttachInterrupt(timer, &resetModule, true);
//timer, tempo (us), repetição
timerAlarmWrite(timer, 30000000, true);
timerAlarmEnable(timer); //habilita a interrupção
}
/***********************************************************
** Função LOOP:
** Faz leitura de corrente e tratamento de carga ligadas
**simultaneamente, não deixando que fique ligadas as 4 saídas
**caso o consumo ultrapasse 9 Amperes
**************************************************************/
void loop () {
Tempo_final = millis();
Tempo_escritaf = millis();
double valorCorrente_AUX = 0;
/******************************************************************************************
**neste programa usarei apenas uma variável de corrente, não guarda o consumo individual
**de cada saida, pois pode ter mais de uma saida simultaneamente
*****************************************************************************************/
valorCorrente_AUX = sensor.getCurrentAC(60); //O número 60 é referente a 60 Hz
if ((Tempo_escritaf - Tempo_escritai) >= 10000) {
tft.fillRoundRect(00, 71, 180, 23, 0, ST77XX_BLACK);
tft.setCursor(50,78);
corrente = valorCorrente_AUX;
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(2);
tft.print(corrente);
tft.print(" A");
Tempo_escritai = millis();
}
if (valorCorrente_AUX >= 29.21) {
if (Maquina_Estado == 0x33) {
Maquina_Estado = 0xFF;
Estado_Maquina = 1;
Desliga_rele ();
Tempo_final = Tempo_inicial + 120000;
Rele1OFF();
Rele2OFF();
Rele3OFF();
Rele4OFF();
}
if (Maquina_Estado == 0xDC) {
Estado_Maquina = 1;
Maquina_Estado = 0xFF;
Desliga_rele ();
Tempo_final = Tempo_inicial + 120000;
Rele1OFF();
Rele2OFF();
Rele3OFF();
Rele4OFF();
}
}
if (Maquina_Estado == 0xFF) {
if ((Tempo_final - Tempo_inicial) >= 120000) {
switch (Estado_Maquina) {
case 1:
digitalWrite(RELAY1, HIGH);
Rele1ON();
delay(18000);
valorCorrente_AUX += sensor.getCurrentAC(60); //O número 60 é referente a 60 Hz
if (valorCorrente_AUX >= 29.21) {
Estado_Maquina = 2;
}
if (valorCorrente_AUX < 29.21) {
Estado_Maquina = 3;
}
Tempo_inicial = millis();
break;
case 2:
digitalWrite(RELAY1, LOW);
Estado_Maquina = 3;
Tempo_inicial = millis();
break;
case 3:
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, HIGH);
Rele2ON();
Rele1OFF();
delay(18000);
valorCorrente_AUX += sensor.getCurrentAC(60); //O número 60 é referente a 60 Hz
if (valorCorrente_AUX >= 29.21) {
Estado_Maquina = 4;
}
if (valorCorrente_AUX < 29.21) {
Estado_Maquina = 5;
}
Tempo_inicial = millis();
break;
case 4:
digitalWrite(RELAY2, LOW);
Estado_Maquina = 5;
Tempo_inicial = millis();
break;
case 5:
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, HIGH);
Rele3ON();
Rele2OFF();
delay(18000);
valorCorrente_AUX += sensor.getCurrentAC(60); //O número 60 é referente a 60 Hz
if (valorCorrente_AUX >= 29.21) {
Estado_Maquina = 6;
}
if (valorCorrente_AUX < 29.21) {
Estado_Maquina = 7;
}
Tempo_inicial = millis();
break;
case 6:
digitalWrite(RELAY3, LOW);
Estado_Maquina = 7;
Tempo_inicial = millis();
break;
case 7:
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, HIGH);
Rele4ON();
Rele3OFF();
delay(18000);
valorCorrente_AUX += sensor.getCurrentAC(60); //O número 60 é referente a 60 Hz
if (valorCorrente_AUX >= 29.21) {
Estado_Maquina = 8;
}
if (valorCorrente_AUX < 29.21) {
Estado_Maquina = 9;
}
Tempo_inicial = millis();
break;
case 8:
digitalWrite(RELAY3, LOW);
Estado_Maquina = 9;
Tempo_inicial = millis();
break;
case 9:
Maquina_Estado = 0xDC;
Estado_Maquina = 11;
Tempo_inicial = millis();
break;
}
}
}
if (Maquina_Estado == 0xDC) {
if ((Tempo_final - Tempo_inicial) >= 120000) {
switch (Estado_Maquina) {
case 11:
digitalWrite(RELAY3, HIGH);
Estado_Maquina = 12;
Tempo_inicial = millis();
Rele3ON();
break;
case 12:
digitalWrite(RELAY2, HIGH);
Estado_Maquina = 13;
Tempo_inicial = millis();
Rele2ON();
break;
case 13:
digitalWrite(RELAY1, HIGH);
Maquina_Estado = 0x33;
Tempo_inicial = millis();
Rele1ON();
break;
}
}
}
//Reinicia a contagem do watchdog time. temporizador de 8 segundos total
//Se a placa travar e passar mais de 8 segundo o controlador irá reiniciar
timerWrite(timer, 0); //reseta o temporizador (alimenta o watchdog)
delay(50);
}