#include <DHT.h>
#define DHTPIN 2
#define pinRojo 11
#define pinVerde 10
#define pinAzul 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(pinRojo, OUTPUT);
pinMode(pinVerde, OUTPUT);
pinMode(pinAzul, OUTPUT);
dht.begin();
}
void loop() {
float temperatura = dht.readTemperature();
if (!isnan(temperatura)) {
int valorLED = map(temperatura, -40, 80, 0, 225);
if (temperatura <= -40) {
analogWrite(pinRojo, 0);
analogWrite(pinVerde, 0);
analogWrite(pinAzul, 225);
} else if (temperatura >= 80) {
analogWrite(pinRojo, 255);
analogWrite(pinVerde, 0);
analogWrite(pinAzul, 0);
} else {
analogWrite(pinRojo, valorLED);
analogWrite(pinVerde, 0);
analogWrite(pinAzul, 255 - valorLED);
}
}
delay(2000);
}