#include <DHT.h>
DHT sensor(2, DHT22);
unsigned long tiempo_actual_1 = 0;
const int PERIODO_1 = 2000 ;
unsigned long tiempo_actual_2 = 0;
const int PERIODO_2 = 2500;
void setup() {
Serial.begin(9600);
sensor.begin();
}
void loop() {
unsigned long contador_tiempo = millis() ;
float temperatura;
float humedad;
// Tarea que produce datos (desde el sensor)
if (contador_tiempo >= tiempo_actual_1 + PERIODO_1) {
tiempo_actual_1 = contador_tiempo;
temperatura = sensor.readTemperature();
humedad = sensor.readHumidity();
Serial.println("Datos obtenidos");
}
// Tarea que consume datos (pantalla)
if (contador_tiempo >= tiempo_actual_2 + PERIODO_2) {
tiempo_actual_2 = contador_tiempo;
Serial.print("Temperatura actual: ");
Serial.print(temperatura);
Serial.println(" °C");
Serial.print("Humedad actual: ");
Serial.print(humedad);
Serial.println(" %RH");
}
}