#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "miscaracteres.h"
#include "DHT.h"
#define DHTPIN A0 // Digital pin connected to the DHT sensor
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT SensorDHT(DHTPIN, DHTTYPE);
//CONFIGURACIÓN DE PANTALLA OLED
const int SCREEN_WIDTH = 128; // OLED display width, in pixels
const int SCREEN_HEIGHT = 64; // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 PantallaOLED(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int contador = 0;
void setup() {
// put your setup code here, to run once:
// Init
Serial.begin(9600);
SensorDHT.begin();
}
void loop() {
// put your main code here, to run repeatedly:
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// int hum = SensorDHT.readHumidity();
// Read temperature as Celsius (the default)
// float temp = SensorDHT.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = SensorDHT.readTemperature(true);
float temp = random(0,5000)/100.00;
int hum = random(0,100);
// se configura columnas y filas
// se configura columnas y filas
pantalla.setCursor(0, 0); //Posiciona la primera letra en linea 1
pantalla.print(hum);
pantalla.print("%"); //Escribe la humedad
if (hum<=40)
{
// DIBUJA SÍMBOLO GOTA DE AGUA Y PRESENTA HUMEDAD ////
//imprime el ícono vacio
pantalla.setCursor(7, 0); //Posiciona la primera letra en linea 1
pantalla.write(4); //Escribe la temperatura Celcius
pantalla.print(" SECA");
}
if (hum>40 && hum <=70)
{
// DIBUJA SÍMBOLO GOTA DE AGUA Y PRESENTA HUMEDAD ////
//imprime el ícono medio
pantalla.setCursor(7, 0); //Posiciona la primera letra en linea 1
pantalla.write(5); //Escribe la temperatura Celcius
pantalla.print(" OPTIMA");
}
if (hum>70)
{
// DIBUJA SÍMBOLO GOTA DE AGUA Y PRESENTA HUMEDAD ////
//imprime el ícono lleno
pantalla.setCursor(7, 0); //Posiciona la primera letra en linea 1
pantalla.write(6); //Escribe la temperatura Celcius
pantalla.print(" ALTA");
}
pantalla.setCursor(0, 1); //Posiciona la primera letra en linea 1
pantalla.print(temp);
pantalla.write(0); //Escribe la temperatura Celcius
if (temp<=15)
{
// DIBUJA SÍMBOLO termometro Y PRESENTA temperatura ////
//imprime el ícono vacio
pantalla.setCursor(7, 1); //Posiciona la primera letra en linea 1
pantalla.write(1); //Escribe la temperatura Celcius
}
if (temp>15 && temp <=30)
{
// DIBUJA SÍMBOLO termometro Y PRESENTA temperatura ////
//imprime el ícono vacio
pantalla.setCursor(7, 1); //Posiciona la primera letra en linea 1
pantalla.write(2); //Escribe la temperatura Celcius
}
if (temp>30)
{
// DIBUJA SÍMBOLO termometro Y PRESENTA temperatura ////
//imprime el ícono vacio
pantalla.setCursor(7, 1); //Posiciona la primera letra en linea 1
pantalla.write(3); //Escribe la temperatura Celcius
}
delay (1000);
pantalla.clear();
}