/*BARREIRA_AVALIACAO_PRATICA_COMPLETO_SET_2024
********************************
********************************
*
ETECAF SISTEMAS EMBARCADOS 2
SEM2 - 3 BIMESTRE - 2024
Avaliação prática
*********ESCREVA SEU NOME COMPLETO ABAIXO***********
*
===> Romeo e matheus <===
*******************************
*******************************
*/
#define potenciometro A2
#define dataPin 2
#define RGBvm 7
#define RGBvd 8
#define RGBaz 9
#define LedTemp 5
#define LedUmid 6
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
dht DHT;
float temp, umid, tempSoma, umidSoma, tempMedia, umidMedia = 0;
long potem, potSoma, potMedia = 0;
int potMap, LedT, LedU = 0;
int tempo = 2000;
void setup()
{
lcd.init();
pinMode(LedTemp, OUTPUT);
pinMode(LedUmid, OUTPUT);
pinMode(RGBvm, OUTPUT);
pinMode(RGBvd, OUTPUT);
pinMode(RGBaz, OUTPUT);
}
void loop()
{
lcd.setBacklight(HIGH);
int readData = DHT.read22(dataPin);
for (int i = 1; i <= 101; i++)
{
temp = DHT.temperature;
tempSoma = temp + tempSoma;
tempMedia = tempSoma / 100;
umid = DHT.humidity;
umidSoma = umid + umidSoma;
umidMedia = umidSoma / 100;
potem = analogRead(A2);
potSoma = potem + potSoma;
potMedia = potSoma / 100;
}
if (tempMedia > 100)
{
digitalWrite(LedTemp, 1);
LedT = 1;
}
else
{
digitalWrite(LedTemp, 0);
LedT = 0;
}
if (umidMedia < 100)
{
digitalWrite(LedUmid, 1);
LedU = 1;
}
else
{
digitalWrite(LedUmid, 0);
LedU = 0;
}
potMap = map(potMedia, 0, 1023, 0, 270);
if (potMap < 90)
{
digitalWrite(RGBvm, 1);
}
else
{
digitalWrite(RGBvm, 0);
}
if (potMap > 90 && potMap < 180)
{
digitalWrite(RGBvd, 1);
}
else
{
digitalWrite(RGBvd, 0);
}
if (potMap > 181)
{
digitalWrite(RGBaz, 1);
}
else
{
digitalWrite(RGBaz, 0);
}
lcd.setCursor(1, 0);
lcd.print("ETECAF SEM2");
lcd.setCursor(7, 1);
lcd.print("RSS");
delay(2000);
lcd.clear();
delay(50);
lcd.setCursor(7, 1);
lcd.print("RSS");
for (int cont = 0; cont < 6; cont++)
{
lcd.scrollDisplayLeft();
delay(50);
}
delay(500);
for (int cont = 0; cont < 12; cont++)
{
lcd.scrollDisplayRight();
delay(50);
}
delay(500);
for (int cont = 0; cont < 6; cont++)
{
lcd.scrollDisplayLeft();
delay(50);
}
delay(500);
lcd.clear();
delay(200);
lcd.setCursor(1, 0);
lcd.print("Temp = ");
lcd.print(tempMedia);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Umid = ");
lcd.print(umidMedia);
lcd.print("%");
delay(tempo);
lcd.clear();
delay(200);
lcd.setCursor(1, 0);
lcd.print("PotMed=");
lcd.print(potMedia);
lcd.setCursor(1, 1);
lcd.print("LedT=");
lcd.print(LedT);
lcd.setCursor(8, 1);
lcd.print("LedU=");
lcd.print(LedU);
delay(tempo);
lcd.clear();
delay(200);
tempSoma = 0;
tempMedia = 0;
umidSoma = 0;
umidMedia = 0;
potSoma = 0;
potMedia = 0;
}