//ETECAF
//SISTEMAS EMBARCADOS 2
//SEM2 - 2021
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Inicializa o display no endereço 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
unsigned long previousMillis = 0; // Variável para armazenar o tempo anterior
int tarefaAtual = 1; // Controle da tarefa atual (1 para tarefa1, 2 para tarefa2)
const unsigned long intervaloTarefa1 = 3000; // 3 segundos para tarefa 1
const unsigned long intervaloTarefa2 = 6000; // 6 segundos para tarefa 2
unsigned long intervaloScroll = 200; // Intervalo para o scroll do display (200 ms)
unsigned long previousMillisScroll = 0; // Armazena o tempo anterior para o scroll
int scrollPosition = 0; // Posição atual do scroll
void setup() {
Serial.begin(9600);
lcd.init();
}
void loop() {
unsigned long currentMillis = millis(); // Tempo atual
if (tarefaAtual == 1) {
tarefa1(currentMillis); // Executa a tarefa 1
} else if (tarefaAtual == 2) {
tarefa2(currentMillis); // Executa a tarefa 2
}
}
void tarefa1(unsigned long currentMillis) {
unsigned long intervalo1 = currentMillis - previousMillis;
if (intervalo1 < intervaloTarefa1) { // Executa por 3 segundos
lcd.setBacklight(HIGH);
lcd.setCursor(6, 0);
lcd.print("SEM2");
lcd.setCursor(6, 1);
lcd.print("ETECAF");
} else {
// Depois de 3 segundos, troca para a tarefa 2
previousMillis = currentMillis; // Atualiza o tempo
tarefaAtual = 2; // Muda para a tarefa 2
lcd.clear(); // Limpa o display antes de começar a tarefa 2
scrollPosition = 0; // Reinicia a posição do scroll
}
}
void tarefa2(unsigned long currentMillis) {
unsigned long intervalo2 = currentMillis - previousMillis;
if (intervalo2 < intervaloTarefa2) { // Executa por 6 segundos
lcd.setCursor(0, 1);
lcd.print("Matheus rodrigues viveiros");
lcd.setCursor(1, 0);
lcd.print("Romeo Santos Schoenfeld");
// Verifica se o tempo de scroll passou o intervalo necessário
if (currentMillis - previousMillisScroll >= intervaloScroll) {
lcd.scrollDisplayLeft();
previousMillisScroll = currentMillis; // Atualiza o tempo do último scroll
scrollPosition++;
if (scrollPosition >= 25) { // 27 é o comprimento do texto "Matheus rodrigues viveiros"
scrollPosition = 0; // Reinicia a posição do scroll
previousMillis = currentMillis; // Atualiza o tempo para trocar de tarefa
tarefaAtual = 1; // Muda para a tarefa 1
lcd.clear(); // Limpa o display antes de voltar para a tarefa 1
}
}
} else {
// Depois de 6 segundos, volta para a tarefa 1
previousMillis = currentMillis; // Atualiza o tempo
tarefaAtual = 1; // Muda para a tarefa 1
lcd.clear(); // Limpa o display antes de voltar para a tarefa 1
}
}