2021-01-05 00:15:16 -03:00
|
|
|
#include <RTClib.h>
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
#include <DHT.h>
|
|
|
|
#define DHT_PIN 4
|
|
|
|
#define DHT_TIPO DHT11
|
|
|
|
DHT SensorDHT(DHT_PIN, DHT_TIPO);
|
|
|
|
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
|
|
|
|
DateTime fecha;
|
|
|
|
RTC_DS3231 reloj;
|
|
|
|
|
|
|
|
byte gota[] = { 0x08, 0x04, 0x06, 0x0F, 0x1D, 0x1F, 0x1F, 0x0E };
|
|
|
|
byte grado[] = { 0x0C, 0x12, 0x12, 0x0C, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
byte dia[] = { 0x04, 0x15, 0x0E, 0x1F, 0x0E, 0x15, 0x04, 0x00 };
|
|
|
|
byte noche[] = { 0x06, 0x0C, 0x18, 0x18, 0x18, 0x1C, 0x0E, 0x07 };
|
|
|
|
|
|
|
|
unsigned long intervalo=950; // tiempo necesario de espera
|
|
|
|
unsigned long intervaloSens=5000;
|
|
|
|
unsigned long previoMillisLoop=0; // millis() retorna unsigned long.
|
|
|
|
unsigned long previoMillisSens=0;
|
|
|
|
|
|
|
|
bool cursor;
|
|
|
|
float humedad, temperatura;
|
|
|
|
//byte humedad, temperatura;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
lcd.begin(16,2);
|
|
|
|
lcd.createChar(1, grado);
|
|
|
|
lcd.createChar(2, gota);
|
|
|
|
lcd.createChar(3, dia);;
|
|
|
|
lcd.createChar(4, noche);
|
|
|
|
SensorDHT.begin();
|
|
|
|
reloj.begin();
|
|
|
|
lcd.home();
|
|
|
|
lcd.print("*** INCIANDO ***");
|
|
|
|
lcd.setCursor(0,1);
|
|
|
|
lcd.print("*** RELOJ ***");
|
|
|
|
//reloj.adjust(DateTime(__DATE__, __TIME__));
|
|
|
|
//humedad = SensorDHT.readHumidity();//(byte)dhtSup.readHumidity() de ser necesario, funcion retorna float;
|
|
|
|
//temperatura = SensorDHT.readTemperature();
|
|
|
|
delay(2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
unsigned long actualMillis = millis();
|
|
|
|
fecha=reloj.now();
|
|
|
|
if ((unsigned long)(actualMillis - previoMillisSens) >= intervaloSens) {
|
|
|
|
humedad = SensorDHT.readHumidity();//(byte)dhtSup.readHumidity() de ser necesario, funcion retorna float;
|
|
|
|
temperatura = SensorDHT.readTemperature();
|
|
|
|
previoMillisSens=millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned long)(actualMillis - previoMillisLoop) >= intervalo) {
|
|
|
|
lcd.clear();
|
|
|
|
lcd.home();
|
|
|
|
lcd.print("T:");
|
|
|
|
lcd.print(temperatura);
|
|
|
|
//lcd.setCursor(4,0);
|
|
|
|
lcd.write(1);
|
|
|
|
lcd.print("C");/*
|
|
|
|
lcd.setCursor(8,0);
|
|
|
|
lcd.print(fecha.day());
|
|
|
|
lcd.print('/');
|
|
|
|
lcd.print(fecha.month());
|
|
|
|
lcd.print('/');
|
|
|
|
lcd.print(fecha.year()-2000);*/
|
|
|
|
lcd.setCursor(0,1);
|
|
|
|
lcd.write(2);
|
|
|
|
lcd.print(':');
|
|
|
|
lcd.print(humedad);
|
|
|
|
lcd.print('%');/*
|
|
|
|
lcd.setCursor(6,1);
|
|
|
|
if(fecha.hour()>6&&fecha.hour()<20) {
|
|
|
|
lcd.write(3);
|
|
|
|
} else {
|
|
|
|
lcd.write(4);
|
|
|
|
}
|
|
|
|
lcd.setCursor(8,1);
|
|
|
|
lcd.print(getHora('h'));
|
|
|
|
lcd.print(':');
|
|
|
|
lcd.print(getHora('m'));
|
|
|
|
if(cursor) {
|
|
|
|
lcd.print(':');
|
|
|
|
} else {
|
|
|
|
lcd.print(" ");
|
|
|
|
}
|
|
|
|
lcd.print(getHora('s'));
|
|
|
|
cursor=!cursor;*/
|
|
|
|
previoMillisLoop = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getHora(char var) {
|
|
|
|
switch (var) {
|
|
|
|
case 'h':
|
|
|
|
if(fecha.hour() < 10) {
|
|
|
|
return ("0"+(String)fecha.hour()); break;
|
|
|
|
} else {
|
|
|
|
return (String)fecha.hour();break;
|
|
|
|
}
|
|
|
|
case 'm':
|
|
|
|
if(fecha.minute() <10) {
|
|
|
|
return ("0"+(String)fecha.minute()); break;
|
|
|
|
} else {
|
|
|
|
return (String)fecha.minute();break;
|
|
|
|
}
|
|
|
|
case 's':
|
|
|
|
if(fecha.second() <10) {
|
|
|
|
return ("0"+(String)fecha.second()); break;
|
|
|
|
} else {
|
|
|
|
return (String)fecha.second();break;
|
|
|
|
}
|
|
|
|
}
|
2022-04-04 14:40:51 -04:00
|
|
|
}
|
|
|
|
|