#include <Wire.h>
#include <Arduino.h>
//#include <TelaRepasse.h>
#include <SD.h>
#include <SPI.h>
File myFile;
int pinoSS = 10; // Pin 53 para Mega / Pin 10 para UNO
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES); // 0x3F 0x27
#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}};
uint8_t colPins[COLS] = {5, 4, 3, 2};
uint8_t rowPins[ROWS] = {9, 8, 7, 6};
Keypad teclado = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String nome;
String nome2;
String LixaAseB1 = "P600-G ";
String LixaAseB0 = "P280 ";
String LixaBseB1 = "P1200PINK";
String LixaBseB0 = "P1200VERD";
String teste = "";
int Rele = A3;
int LEDvermelho = A0;
int LEDverde = A2;
int LEDamarelo = A1;
int inicio2 = 0;
int inicio3 = 0;
int inicio1T = 0;
int inicio2T = 0;
int inicio3T = 0;
int inicio1FF;
int inicio2FF;
int inicio3FF;
int passo1 = 0;
int passo2 = 0;
int passo3 = 0;
int tempoD = 10;
int tempoD2 = 10;
int contagem = 0;
int contando = 0;
int contando1 = 0;
int contando2 = 0;
int contando3 = 0;
int contando1A = 0;
int contando2A = 0;
int contando3A = 0;
int selecionado = 0;
int percentual = 0;
int produtoSelecionado;
int PS;
int TL = 0;
float CP1 = 0;
float CP2 = 0;
float CPtotal = 0;
float inicio1;
float inicio1F;
float inicio2F;
float inicio3F;
float FRemocao = 0.00;
float FRemocaoFF = FRemocao * 10;
bool contadorD = false;
bool contadorD1 = true;
bool MotorTrabalhando = false;
bool contagemIniciada = false;
// Telas
bool TelaInicio = true;
bool TelaRepasse = false;
bool TelaProduto = false;
bool TelaConfig = false;
bool TelaRemocao = false;
bool TelaTempoLivre = false;
bool TelaProd = false;
bool TelaContandoA = false;
bool TelaContandoB = false;
bool TelaContandoC = false;
static int escolha = 0;
static int contador = 0;
static unsigned long tempoInicial = millis();
const unsigned long TEMPO_TOTAL = 15000;
byte customChar[] = {
B00000,
B00100,
B01110,
B11111,
B11111,
B01110,
B00100,
B00000};
// Definição dos produtos e tempos
String nomes[] = {
// DIGITE ABAIXO OS NOMES DOS PRODUTOS COM SEUS INDICES
"TIPO", // PRODUTO 1
"TIPO", // PRODUTO 2
"TIPO", // PRODUTO 3
"TIPO", // PRODUTO 4
"TIPO", // PRODUTO 5
"TIPO", // PRODUTO 6
"TIPO", // PRODUTO 7
"TIPO", // PRODUTO 8
//***************************************************************************************
};
// DIGITE ABAIXO OS TEMPOS DOS PASSOS 1, 2, 3 DOS PRODUTOS P1[], P2[], P3[]...
int P98[] = {11.1110f, 10, 0};
int P11[] = {111.1110f, 60, 0}; //{111.1110f, 60, 0};
int P12[] = {98.3606f, 60, 0};
int P13[] = {130.4340f, 60, 0};
int P14[] = {857.1428f, 0, 60};
int P15[] = {176.47f, 60, 0};
int P16[] = {162.1621f, 60, 0};
int P17[] = {0.7142f, 0, 0};
int P18[] = {206.8965f, 60, 0};
//***************************************************************************************
// Função para obter os tempos de um produto
void obterTempos(int produto[], String &nome, float &inicio1, int &inicio2, int &inicio3)
{
inicio1 = produto[0];
inicio2 = produto[1];
inicio3 = produto[2];
nome = "TIPO"; // nome = nomes[0];
}
void Inicio()
{
// Telas
TelaInicio = true;
TelaRepasse = false;
TelaProduto = false;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
contadorD == false;
lcd.clear();
inicio1 = 0;
inicio2 = 0;
inicio3 = 0;
inicio1T = 0;
inicio2T = 0;
inicio3T = 0;
// AnimacaoTotal();
lcd.setCursor(0, 0);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 1);
lcd.print(F("| |"));
lcd.setCursor(0, 3);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 2);
lcd.print(F("| |"));
lcd.setCursor(0, 1);
lcd.print(F("| DIGITE O TIPO |"));
lcd.setCursor(8, 2);
lcd.print(F("["));
lcd.setCursor(11, 2);
lcd.print(F("]"));
lcd.setCursor(7, 3);
lcd.print(F("R:"));
lcd.print(FRemocao);
}
void TelaQuadrado()
{
// exiba o título da tela
lcd.setCursor(0, 0);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 1);
lcd.print(F("| |"));
lcd.setCursor(0, 2);
lcd.print(F("| |"));
lcd.setCursor(0, 3);
lcd.print(F("*------------------*"));
}
void TelaPasseA()
{
bool contadorD = true; // defina o contadorD como verdadeiro
lcd.clear(); // limpe a tela LCD
TelaQuadrado();
// exiba o tipo de operação e o tempo restante
lcd.setCursor(6, 0);
lcd.print(F("TIPO: "));
lcd.print(escolha);
lcd.setCursor(1, 1);
lcd.print(F("(A)"));
lcd.setCursor(13, 1);
lcd.print(F("T: "));
if (inicio1FF >= 100)
{
lcd.setCursor(16, 1);
}
else if (inicio1FF >= 10)
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
else
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
lcd.print(inicio1FF);
// exiba o número da lixa e a taxa de remoção
PLixaA();
lcd.setCursor(13, 2);
lcd.print(F("R:"));
lcd.print(FRemocao);
delay(500); // aguarde meio segundo
}
void TelaPasseB()
{
bool contadorD = true; // defina o contadorD como verdadeiro
lcd.clear(); // limpe a tela LCD
TelaQuadrado();
// exiba o tipo de operação e o tempo restante
lcd.setCursor(6, 0);
lcd.print(F("TIPO: "));
lcd.print(escolha);
lcd.setCursor(1, 1);
if (inicio2T > 0)
{
lcd.print(F("(B)"));
}
if (inicio3T > 0)
{
lcd.print(F("(C)"));
}
lcd.setCursor(13, 1);
lcd.print(F("T: "));
if (inicio2FF >= 100)
{
lcd.setCursor(16, 1);
}
else if (inicio2FF >= 10)
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
else
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
lcd.print(inicio2FF);
// exiba o número da lixa e a taxa de remoção
LixaB2();
lcd.setCursor(13, 2);
lcd.print(F("R:"));
lcd.print(FRemocao);
delay(500); // aguarde meio segundo
}
void setup()
{
Serial.begin(9600);
pinMode(Rele, OUTPUT);
pinMode(LEDvermelho, OUTPUT);
pinMode(LEDverde, OUTPUT);
pinMode(LEDamarelo, OUTPUT);
digitalWrite(LEDverde, HIGH);
digitalWrite(LEDvermelho, LOW);
digitalWrite(LEDamarelo, LOW);
digitalWrite(Rele, LOW);
pinMode(pinoSS, OUTPUT);
// Configura o LCD
lcd.init();
lcd.begin(20, 4);
lcd.createChar(0, customChar);
lcd.home();
lcd.setBacklight(HIGH);
// inicia o programa
Inicio();
}
void AnimacaoTotal()
{
for (int col = 0; col < 20; col++)
{
for (int linha = 0; linha < 4; linha++)
{
lcd.setCursor(col, linha);
lcd.print(F(" "));
delay(1);
lcd.setCursor(col, linha);
lcd.write(0);
}
}
}
void cartao()
{ // Executado uma vez quando ligado o Arduino
if (SD.begin())
{ // Inicializa o SD Card
delay(1000);
Serial.println(F("SD Card pronto para uso.")); // Imprime na tela
}
else
{
Serial.println(F("Falha na inicialização do SD Card."));
return;
}
myFile = SD.open("produtos.txt"); // Abre o Arquivo
if (myFile)
{
teste = myFile.parseInt();
}
lcd.setCursor(0, 2);
lcd.print(teste);
}
void SelecionaProduto()
{
inicio1F = inicio1 * FRemocao + 1;
inicio1FF = round(inicio1F);
inicio1T = inicio1FF;
inicio2T = inicio2;
inicio3T = inicio3;
inicio2FF = inicio2;
inicio3FF = inicio3;
Selecionado();
}
void CRemocao()
{
if (FRemocao < 0.01)
{
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F(" "));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F(" "));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F(" "));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F(" "));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F(" "));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F(" "));
delay(50);
lcd.setCursor(3, 3);
lcd.print(F("AJUSTE REMOCAO"));
delay(50);
}
}
void Selecionado()
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = true;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
if (FRemocao < 0.01)
{
CRemocao();
}
else
{
contadorD == true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 1);
lcd.print(F("| |"));
lcd.setCursor(0, 3);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 2);
lcd.print(F("| |"));
lcd.setCursor(6, 0);
lcd.print(F("TIPO:"));
lcd.print(escolha);
lcd.setCursor(1, 1);
lcd.print(F("(A)"));
lcd.print(F(" T:"));
lcd.print(inicio1FF);
lcd.setCursor(1, 2);
PLixaA();
lcd.setCursor(10, 1);
if (inicio2FF > 0)
{
lcd.print(F("(B)"));
}
if (inicio3FF > 0)
{
lcd.print(F("(C)"));
}
lcd.print(F(" T:"));
if (inicio2FF > 0)
{
lcd.print(inicio2FF);
}
else
{
lcd.print(inicio3FF);
}
lcd.setCursor(10, 2);
PLixaB();
lcd.setCursor(7, 3);
lcd.print(F("R:"));
lcd.print(FRemocao);
delay(500);
}
}
void LogSerial()
{
Serial.print(F("Produto: "));
Serial.print(F("Tipo: "));
Serial.print(escolha);
Serial.print(inicio1FF);
Serial.print(F(" | Passo.B:"));
Serial.print(inicio2);
Serial.print(F(" | Passo.C:"));
Serial.print(inicio3);
}
void LixaA()
{
if (inicio2T > 0)
{
lcd.setCursor(11, 1);
lcd.print(F(" ")); // 20
lcd.setCursor(11, 1);
lcd.print(LixaAseB1);
Serial.print(F(" | Lixa A:"));
Serial.println(LixaAseB1);
}
if (inicio2T <= 0)
{
lcd.setCursor(11, 1);
lcd.print(F(" ")); // 20
lcd.setCursor(11, 1);
lcd.print(LixaAseB0);
Serial.print(F(" | Lixa A:"));
Serial.println(LixaAseB0);
}
}
void PLixaA()
{
if (inicio2T > 0)
{
lcd.setCursor(1, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(1, 2);
lcd.print(LixaAseB1);
Serial.print(F(" | Lixa A:"));
Serial.println(LixaAseB1);
}
if (inicio2T <= 0)
{
lcd.setCursor(1, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(1, 2);
lcd.print(LixaAseB0);
Serial.print(F(" | Lixa A:"));
Serial.println(LixaAseB0);
}
}
void PLixaB()
{
if (inicio3T > 0)
{
lcd.setCursor(10, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(10, 2);
lcd.print(LixaBseB0);
}
if (inicio3T <= 0)
{
lcd.setCursor(10, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(10, 2);
lcd.print(LixaBseB1);
}
}
void LixaB2()
{
if (inicio3T > 0)
{
lcd.setCursor(1, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(1, 2);
lcd.print(LixaBseB0);
}
if (inicio3T <= 0)
{
lcd.setCursor(1, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(1, 2);
lcd.print(LixaBseB1);
}
}
void AcionaMaquina()
{
digitalWrite(LEDamarelo, HIGH);
delay(50);
digitalWrite(Rele, HIGH);
delay(500);
digitalWrite(Rele, LOW);
delay(50);
digitalWrite(LEDamarelo, LOW);
}
void PiscaLcd()
{
lcd.setBacklight(LOW);
delay(100);
lcd.setBacklight(HIGH);
delay(100);
lcd.setBacklight(LOW);
delay(100);
lcd.setBacklight(HIGH);
delay(100);
lcd.setBacklight(LOW);
delay(100);
lcd.setBacklight(HIGH);
delay(100);
}
void LimparL0()
{
lcd.setCursor(0, 0); // Define a posição do cursor para a primeira linha
for (int i = 0; i < 20; i++)
{
lcd.print(F(" ")); // Imprime o caractere '#' em cada coluna da primeira linha
}
}
void LimparL1()
{
lcd.setCursor(0, 1); // Define a posição do cursor para a primeira linha
for (int i = 0; i < 20; i++)
{
lcd.print(F(" ")); // Imprime o caractere '#' em cada coluna da primeira linha
}
}
void LimparL2()
{
lcd.setCursor(0, 2); // Define a posição do cursor para a primeira linha
for (int i = 0; i < 20; i++)
{
lcd.print(F(" ")); // Imprime o caractere '#' em cada coluna da primeira linha
}
}
void LimparL3()
{
lcd.setCursor(0, 3); // Define a posição do cursor para a primeira linha
for (int i = 0; i < 20; i++)
{
lcd.print(F(" ")); // Imprime o caractere '#' em cada coluna da primeira linha
}
}
void PreencherL3()
{
lcd.setCursor(0, 3); // Define a posição do cursor para a primeira linha
for (int i = 0; i < 20; i++)
{
lcd.write(0); // Imprime o caractere '#' em cada coluna da primeira linha
}
}
void AnimacaoPasso2()
{
PreencherL3();
lcd.setCursor(11, 2);
lcd.print(F(" "));
lcd.setCursor(11, 2);
lcd.print(F("----OK---"));
delay(5000);
LimparL3();
LixaA();
}
void ContagemProntos()
{
CPtotal = CP1 + CP2 / 2;
lcd.setCursor(0, 8);
}
void desenharMenu()
{
lcd.setCursor(0, 0);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 1);
lcd.print(F("| |"));
lcd.setCursor(0, 3);
lcd.print(F("*------------------*"));
lcd.setCursor(0, 2);
lcd.print(F("| |"));
}
void PPassoA()
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = true;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
TelaPasseA();
Serial.println(F("****** : Inicio do PASSO A"));
Serial.print(F("TEMPO:"));
Serial.print(inicio1T);
Serial.println(F(" seg"));
// comanda os leds
digitalWrite(LEDvermelho, HIGH);
digitalWrite(LEDverde, LOW);
digitalWrite(LEDamarelo, LOW);
// aciona a máquina se contador1A for 0
if (contando1A == 0)
{
AcionaMaquina();
MotorTrabalhando = true;
Serial.println(F("Status do Motor: Ligado"));
}
while (inicio1T > 0)
{ // enquanto o tempo não chegar a 0
if (inicio1T >= 100)
{
lcd.setCursor(16, 1);
}
else if (inicio1T >= 10)
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
else
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
contando1A = 0;
contagemIniciada = false; // zera a variável de controle da barra de progresso
}
lcd.print(inicio1T);
if (inicio1T % 2 == 0)
{
lcd.setCursor(1, 1);
lcd.print(F("(A)"));
}
else
{
lcd.setCursor(1, 1);
lcd.print(F(" "));
}
delay(1000);
inicio1T--;
passo1 = 1;
// Barra
lcd.setCursor(2, 3);
lcd.write(0);
lcd.setCursor(2, 3);
int progresso = map(inicio1T, 0, inicio1FF, 0, 15);
for (int i = 14; i >= 0; i--)
{
if (i >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F("-"));
}
}
lcd.write(0);
// lcd.setCursor(19, 3);
// lcd.write(0);
}
// aciona a máquina se contador1A for 0
if (contando1A == 0)
{
lcd.setCursor(1, 1);
lcd.print(F("(A)"));
AcionaMaquina();
MotorTrabalhando = false;
lcd.setCursor(0, 3);
// lcd.print(F(" "));
contagemIniciada = false;
Serial.println(F("Status do Motor: Desligado"));
Serial.println(F("********* : Fim do PASSO A"));
Serial.println(F("*************************"));
}
// comanda os leds
digitalWrite(LEDverde, HIGH);
digitalWrite(LEDvermelho, LOW);
digitalWrite(Rele, LOW);
// pisca o lcd
PiscaLcd();
lcd.setCursor(7, 1);
delay(50);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(3000);
passo1 = 0;
contando1 = 0;
inicio1T = inicio1FF;
tempoInicial = millis();
CP1 += 0.5;
Selecionado();
}
void PPassoB()
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = true;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
TelaPasseB();
Serial.println(F("****** : Inicio do PASSO B"));
Serial.print(F("TEMPO:"));
Serial.print(inicio2T);
Serial.println(F(" seg"));
// comanda os leds
digitalWrite(LEDvermelho, HIGH);
digitalWrite(LEDverde, LOW);
digitalWrite(LEDamarelo, LOW);
// aciona a máquina se contador1A for 0
if (contando2A == 0)
{
AcionaMaquina();
MotorTrabalhando = true;
Serial.println(F("Status do Motor: Ligado"));
}
while (inicio2T > 0)
{ // enquanto o tempo não chegar a 0
if (inicio2T >= 100)
{
lcd.setCursor(16, 1);
}
else if (inicio2T >= 10)
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
else
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
contando1A = 0;
contagemIniciada = false; // zera a variável de controle da barra de progresso
}
lcd.print(inicio2T);
if (inicio2T % 2 == 0)
{
lcd.setCursor(1, 1);
lcd.print(F("(B)"));
}
else
{
lcd.setCursor(1, 1);
lcd.print(F(" "));
}
delay(1000);
inicio2T--;
passo2 = 1;
// Barra
lcd.setCursor(2, 3);
lcd.write(0);
lcd.setCursor(2, 3);
int progresso = map(inicio2T, 0, inicio2FF, 0, 15);
for (int i = 14; i >= 0; i--)
{
if (i >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F("-"));
}
}
lcd.write(0);
// lcd.setCursor(19, 3);
// lcd.write(0);
}
// aciona a máquina se contador1A for 0
if (contando2A == 0)
{
lcd.setCursor(1, 1);
lcd.print(F("(B)"));
AcionaMaquina();
MotorTrabalhando = false;
lcd.setCursor(0, 3);
// lcd.print(F(" "));
contagemIniciada = false;
Serial.println(F("Status do Motor: Desligado"));
Serial.println(F("********* : Fim do PASSO B"));
Serial.println(F("*************************"));
}
// comanda os leds
digitalWrite(LEDverde, HIGH);
digitalWrite(LEDvermelho, LOW);
digitalWrite(Rele, LOW);
// pisca o lcd
PiscaLcd();
lcd.setCursor(7, 1);
delay(50);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(3000);
passo2 = 0;
contando2 = 0;
inicio2T = inicio2FF;
tempoInicial = millis();
contagemIniciada = true;
CP2 += 0.5;
Selecionado();
}
void updateLCD(int tempo) {
lcd.setCursor(7, 2);
if (tempo >= 99) {
lcd.print("[ ]");
lcd.setCursor(8, 2);
lcd.print(tempo);
} else if (tempo <= 9) {
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(10, 2);
lcd.print(tempo);
} else if (tempo <= 99 && tempo >= 10) {
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(9, 2);
lcd.print(tempo);
} else {
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(8, 2);
lcd.print(tempo);
}
// Barra
lcd.setCursor(2, 3);
int progresso = map(tempo, 0, 500, 16, 1);
for (int i = 16; i >= 0; i--) {
if (i >= progresso) {
lcd.write(0);
} else {
lcd.print(F("-"));
}
}
}
void PPassoC()
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = true;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
TelaPasseB();
Serial.println(F("****** : Inicio do PASSO C"));
Serial.print(F("TEMPO:"));
Serial.print(inicio3T);
Serial.println(F(" seg"));
// comanda os leds
digitalWrite(LEDvermelho, HIGH);
digitalWrite(LEDverde, LOW);
digitalWrite(LEDamarelo, LOW);
// aciona a máquina se contador1A for 0
if (contando3A == 0)
{
AcionaMaquina();
MotorTrabalhando = true;
Serial.println(F("Status do Motor: Ligado"));
}
while (inicio3T > 0)
{ // enquanto o tempo não chegar a 0
if (inicio3T >= 100)
{
lcd.setCursor(16, 1);
}
else if (inicio3T >= 10)
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
}
else
{
lcd.setCursor(16, 1);
lcd.print(F(" "));
contando3A = 0;
contagemIniciada = false; // zera a variável de controle da barra de progresso
}
lcd.print(inicio3T);
if (inicio3T % 2 == 0)
{
lcd.setCursor(1, 1);
lcd.print(F("(C)"));
}
else
{
lcd.setCursor(1, 1);
lcd.print(F(" "));
}
delay(1000);
inicio3T--;
passo3 = 1;
// Barra
lcd.setCursor(2, 3);
lcd.write(0);
lcd.setCursor(2, 3);
int progresso = map(inicio3T, 0, inicio3FF, 0, 15);
for (int i = 14; i >= 0; i--)
{
if (i >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F("-"));
}
}
lcd.write(0);
// lcd.setCursor(19, 3);
// lcd.write(0);
}
// aciona a máquina se contador1A for 0
if (contando3A == 0)
{
lcd.setCursor(1, 1);
lcd.print(F("(C)"));
AcionaMaquina();
MotorTrabalhando = false;
lcd.setCursor(0, 3);
// lcd.print(F(" "));
contagemIniciada = false;
Serial.println(F("Status do Motor: Desligado"));
Serial.println(F("********* : Fim do PASSO C"));
Serial.println(F("*************************"));
}
// comanda os leds
digitalWrite(LEDverde, HIGH);
digitalWrite(LEDvermelho, LOW);
digitalWrite(Rele, LOW);
// pisca o lcd
PiscaLcd();
lcd.setCursor(7, 1);
delay(50);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("( )"));
delay(50);
lcd.setCursor(7, 1);
lcd.print(F("(FIM)"));
delay(3000);
passo2 = 0;
passo3 = 0;
contando3 = 0;
contando2 = 0;
inicio3T = inicio3FF;
tempoInicial = millis();
contagemIniciada = true;
CP2 += 0.5;
Selecionado();
}
void TelaTLivre()
{
}
void loop()
{
String nome3 = "TIPO";
char tecla = teclado.getKey();
if (tecla == '0')
{ // Voltar para a seleção de produto
escolha = 0;
contador = 0;
Inicio();
TelaInicio = true;
return;
}
if (TelaRepasse && tecla == '*') {
if (tempoD >= 1 && tempoD <= 500) {
tempoD--;
if (tempoD > 500) {
tempoD = 500;
}
updateLCD(tempoD);
}
} else if (TelaRepasse && tecla == '7') {
if (tempoD >= 10 && tempoD <= 500) {
tempoD -= 10;
if (tempoD > 500) {
tempoD = 500;
}
updateLCD(tempoD);
}
} else if (TelaRepasse && tecla == '9') {
if (tempoD >= 1 && tempoD <= 490) {
tempoD += 10;
updateLCD(tempoD);
} else if (tempoD >= 491 && tempoD <= 500) {
tempoD = 500;
updateLCD(tempoD);
}
} else if (TelaRepasse && tecla == '#' && !TelaInicio) {
if (tempoD >= 1 && tempoD <= 499) {
tempoD++;
updateLCD(tempoD);
} else if (tempoD == 500) {
updateLCD(tempoD);
}
}
if (tecla && TelaInicio && contador < 2)
{
if ((tecla >= '0' && tecla <= '9') || (contador == 0 && tecla == '0'))
{
escolha = (escolha * 10) + (tecla - '0');
contador++;
lcd.setCursor(9, 2);
if (escolha == 0)
{
lcd.print(F("0"));
}
else
{
lcd.print(escolha);
}
}
}
else if (contador == 2)
{
lcd.setCursor(16, 1);
}
if (tecla == 'A')
{
if (TelaRepasse == true)
{
int tempoDFF;
tempoDFF = tempoD;
digitalWrite(LEDvermelho, HIGH);
digitalWrite(LEDverde, LOW);
digitalWrite(LEDamarelo, LOW);
AcionaMaquina();
while (tempoD >= 0)
{ // Enquanto o tempo não chegar a 100
if (tempoD >= 10)
{
lcd.setCursor(9, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(9, 2);
lcd.print(tempoD); // 20
}
else
{
lcd.setCursor(9, 2);
lcd.print(F("0 ")); // 20
lcd.setCursor(10, 2);
lcd.print(tempoD); // 20
}
// Barra
lcd.setCursor(2, 3);
int progresso = map(tempoD, 0, tempoDFF, 1, 16);
for (int i = 16; i >= 0; i--)
{
if (i >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F("-"));
}
}
delay(1000); // Aguarda 1 segundo
tempoD--; // Decrementa o tempo em 1 segundo
}
if (tempoD <= 0)
{
lcd.setCursor(9, 2);
lcd.print(F("OK")); // 20
// AnimacaoRepasse();
digitalWrite(LEDverde, HIGH);
digitalWrite(LEDvermelho, LOW);
AcionaMaquina();
PiscaLcd();
delay(5000);
desenharMenu();
lcd.setCursor(2, 1);
lcd.print(F("TEMPO DE REPASSE")); // 20
tempoD = tempoD2;
if (tempoD2 >= 10)
{
lcd.setCursor(9, 2);
lcd.print(F(" ")); // 20
lcd.setCursor(9, 2);
lcd.print(tempoD); // 20
}
else
{
lcd.setCursor(8, 2);
lcd.print(F("0")); // 20
lcd.setCursor(10, 2);
lcd.print(tempoD); // 20
}
}
}
}
if (tecla == 'A' && produtoSelecionado > 0 && TelaProduto == true && FRemocao > 0.01)
{
if (TelaProduto == true)
{
PPassoA();
}
}
if (tecla == 'B' && produtoSelecionado > 0 && TelaProduto == true)
{
if (inicio2T > 0)
{
PPassoB();
}
}
if (tecla == 'C' && produtoSelecionado > 0 && TelaProduto == true)
{
if (inicio3T > 0)
{
PPassoC();
}
}
if (tecla == 'C')
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = false;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = true;
TelaProd = false;
//
int i = 0;
int tempo = 0;
escolha = 0;
contador = 0;
contadorD = false;
lcd.clear();
TelaQuadrado();
lcd.setCursor(4, 1);
lcd.print(F("TEMPO LIVRE"));
lcd.setCursor(7, 2);
lcd.print(F("[ ]"));
int contador = 0; // declaração da variável fora do loop while
while (TelaTempoLivre == true && contador < 3)
{
char tecla = teclado.getKey();
if ((tecla >= '0' && tecla <= '9') || (contador == 0 && tecla == '0'))
{
escolha = (escolha * 10) + (tecla - '0');
contador++;
lcd.setCursor(8, 2);
if (escolha == 0)
{
lcd.print(F("0"));
lcd.print("i");
escolha = 0;
contador = 0;
TelaTempoLivre = false;
Inicio();
}
else
{
lcd.print(escolha);
}
}
if (tecla == 'A')
{ // adicionado uma verificação se a tecla A foi pressionada
MotorTrabalhando = true;
contagemIniciada = true;
AcionaMaquina();
// comanda os leds
digitalWrite(LEDverde, LOW);
digitalWrite(LEDvermelho, HIGH);
int tempo = escolha; // o tempo será igual ao valor digitado
lcd.setCursor(2, 3);
lcd.write(0);
for (int i = tempo; i >= 0; i--)
{ // contador regressivo
lcd.setCursor(2, 3);
int progresso = map(i * 1, 0, escolha, 16, 1);
for (int ii = 16; ii >= 0; ii--)
{
if (ii >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F("-"));
}
}
lcd.setCursor(17, 3);
lcd.write(0);
lcd.setCursor(8, 2);
if (i > 99)
{
lcd.setCursor(8, 2);
lcd.print(i);
}
lcd.print(i);
if (i <= 99 and i >= 10)
{
lcd.setCursor(8, 2);
lcd.print(F("0"));
lcd.print(i);
}
if (i <= 9 and i > 0)
{
lcd.setCursor(8, 2);
lcd.print(F("00"));
lcd.print(i);
}
delay(1000); // espera um segundo antes de decrementar o contador
}
AcionaMaquina();
PiscaLcd();
delay(50);
lcd.setCursor(7, 2);
lcd.print(F("[FIM]"));
delay(50);
lcd.setCursor(7, 2);
lcd.print(F("[ ]"));
delay(50);
lcd.setCursor(7, 2);
lcd.print(F("[FIM]"));
delay(50);
lcd.setCursor(7, 2);
lcd.print(F("[ ]"));
delay(50);
lcd.setCursor(7, 2);
lcd.print(F("[FIM]"));
delay(50);
lcd.setCursor(7, 2);
lcd.print(F("[FIM]"));
delay(50);
MotorTrabalhando = false;
contagemIniciada = false;
digitalWrite(LEDverde, HIGH);
digitalWrite(LEDvermelho, LOW);
i = tempo;
contador = 0;
}
// pisca o lcd
}
}
if (tecla == '1' and TelaConfig == true and TelaProd == false and TelaRepasse == false and TelaInicio == false)
{
lcd.clear();
desenharMenu();
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = false;
TelaConfig = false;
TelaRemocao = true;
TelaTempoLivre = false;
TelaProd = false;
//
lcd.setCursor(2, 1);
lcd.print(F("AJUSTE: REMOCAO")); // 20
lcd.setCursor(8, 3);
lcd.print(FRemocao); // 20
lcd.setCursor(2, 2);
int progresso = map(FRemocao * 100, 0, 100, 16, 1);
for (int i = 16; i >= 0; i--)
{
if (i >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F(" "));
}
}
}
if (tecla == '3' and TelaConfig == true and TelaProd == false and TelaRepasse == false and TelaInicio == false)
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = false;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = true;
//
CPtotal = CP1 + CP2;
CPtotal = CPtotal;
lcd.clear();
desenharMenu();
lcd.setCursor(2, 1);
lcd.print(F("PRODUCAO DO DIA")); // 20
lcd.setCursor(7, 3);
lcd.print(CPtotal); // 20
if (CPtotal > 1)
{
// Barra
lcd.setCursor(2, 2);
int progresso = map(CPtotal, 0, 100, 16, 1);
for (int i = 16; i >= 0; i--)
{
if (i >= progresso)
{
lcd.write(0);
}
else
{
lcd.print(F(" "));
}
}
}
if (tecla == 'D')
{
// Telas
TelaInicio = false;
TelaRepasse = true;
TelaProduto = false;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
contadorD == true;
lcd.clear();
desenharMenu();
lcd.setCursor(2, 1);
lcd.print(F("TEMPO DE REPASSE")); // 20
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(9, 2);
lcd.print(tempoD); // 20
lcd.setCursor(2, 3);
tempoD = tempoD;
lcd.setCursor(7, 2);
if (tempoD >= 99)
{
lcd.print("[ ]");
lcd.setCursor(8, 2);
lcd.print(tempoD);
}
if (tempoD > 500)
{
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(8, 2);
tempoD = 500;
lcd.print(tempoD);
}
if (tempoD <= 99 and tempoD >= 10)
{
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(9, 2);
lcd.print(tempoD);
}
if (tempoD <= 9 and tempoD >= 1)
{
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(10, 2);
lcd.print(tempoD);
}
}
if (tecla == 'C')
{
// Telas
TelaInicio = false;
TelaRepasse = true;
TelaProduto = false;
TelaConfig = false;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
contadorD == true;
lcd.clear();
desenharMenu();
lcd.setCursor(2, 1);
lcd.print(F("TEMPO DE REPASSE")); // 20
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(9, 2);
lcd.print(tempoD); // 20
lcd.setCursor(2, 3);
tempoD = tempoD;
lcd.setCursor(7, 2);
if (tempoD >= 99)
{
lcd.print("[ ]");
lcd.setCursor(8, 2);
lcd.print(tempoD);
}
if (tempoD > 500)
{
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(8, 2);
tempoD = 500;
lcd.print(tempoD);
}
if (tempoD <= 99 and tempoD >= 10)
{
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(9, 2);
lcd.print(tempoD);
}
if (tempoD <= 9 and tempoD >= 1)
{
lcd.setCursor(7, 2);
lcd.print("[ ]");
lcd.setCursor(10, 2);
lcd.print(tempoD);
}
}
// # *************************
}
if (TelaInicio == true)
{
if (escolha == 99)
{
if (TelaInicio == true || TelaRepasse == true || TelaRemocao == true || TelaProd == true)
{
// Telas
TelaInicio = false;
TelaRepasse = false;
TelaProduto = false;
TelaConfig = true;
TelaRemocao = false;
TelaTempoLivre = false;
TelaProd = false;
//
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("1:Rem"));
lcd.setCursor(7, 0);
lcd.print(F("2:---"));
lcd.setCursor(15, 0);
lcd.print(F("3:Pro"));
lcd.setCursor(0, 1);
lcd.print(F("4:---"));
lcd.setCursor(7, 1);
lcd.print(F("5:---"));
lcd.setCursor(15, 1);
lcd.print(F("6:---"));
lcd.setCursor(0, 2);
lcd.print(F("7:---"));
lcd.setCursor(7, 2);
lcd.print(F("8:---"));
lcd.setCursor(15, 2);
lcd.print(F("9:---"));
lcd.setCursor(6, 3);
lcd.print(F("0:Voltar"));
}
}
if (escolha == 97)
{
if (contadorD == false and TelaInicio == true)
{
cartao();
}
}
if (escolha == 98)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P98, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 11 *************************
if (escolha == 11)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P11, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 12 *************************
if (escolha == 12)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P12, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 13 *************************
if (escolha == 13)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P13, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 14 *************************
if (escolha == 14)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P14, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 15 *************************
if (escolha == 15)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P15, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 16 *************************
if (escolha == 16)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P16, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 17 *************************
if (escolha == 17)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P17, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
// 18 *************************
if (escolha == 18)
{
if (contadorD == false and TelaInicio == true)
{
produtoSelecionado = escolha;
obterTempos(P18, nome, inicio1, inicio2, inicio3);
nome = nomes[(produtoSelecionado - 1)];
SelecionaProduto();
TelaInicio = false;
TelaProduto = true;
contagemIniciada = true;
}
}
}
}