#include <DHT.h>
#include <LiquidCrystal.h>
#define DHTPIN A1
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
LiquidCrystal lcd(12,11,10,5,4,3,2);
// int: valores inteiros
// float: valores reais
// long: usado para tempo
// bool: Verdadeiro ou Falso
long tempoLED;
long tempoLCD;
int cont = 0;
bool mostrar = true;
int pinTrig = 7;
int pinEcho = 8;
long tempoHC;
float distancia; // Valores reais
float temperatura;
float umidade;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.print("Ola Estranho!");
tempoLED = millis();
pinMode(13, OUTPUT);
while(millis() < 2000){}
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(millis() - tempoLED < 500){
digitalWrite(13,HIGH);
}
else{
digitalWrite(13,LOW);
}
if(millis()- tempoLED > 2500){
tempoLED = millis();
}
if(cont == 0 && mostrar == true){
digitalWrite(pinTrig, LOW);
delayMicroseconds(10);
digitalWrite(pinTrig, HIGH);
delayMicroseconds(10);
digitalWrite(pinTrig, LOW);
tempoHC = pulseIn(pinEcho, HIGH);
distancia = (tempoHC * 0.0034) / 2;
lcd.clear();
lcd.print("Distancia: ");
lcd.setCursor(10,1);
lcd.print(distancia);
mostrar = false;
}
if(cont == 1 && mostrar == true){
temperatura = dht.readTemperature();
lcd.clear();
lcd.print("Temperatura: ");
lcd.setCursor(10,1);
lcd.print(temperatura);
mostrar = false;
}
if(cont == 2 && mostrar == true){
umidade = dht.readHumidity();
lcd.clear();
lcd.print("Umidade: ");
lcd.setCursor(10,1);
lcd.print(umidade);
mostrar = false;
}
if(millis() - tempoLCD > 3000){
Serial.println(cont);
cont++;
tempoLCD = millis();
if(cont>2){
cont=0;
}
mostrar = true;
}
}