Hi there,
I wish to make a little thermometer with one WS2812 led and a DHT11 sensor.
I have two questions here.
1). I was trying to delay the sensor reading for 2s, but then the fading of WS2812 will not work as expected.
2). I wish to add a color fading definitions to it, like: Red, Yellow, Orange, Green, White and Blue (going in and out like Pulsing).
#include <DHT.h>
#include <Adafruit_NeoPixel.h>
#define DHT_PIN 2
#define DHT_TYPE DHT11 // DHT 11
//#define DHT_TYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHT_TYPE DHT21 // DHT 21 (AM2301)
#define NEO_PIN 6
#define NEO_NUM_LEDS 1
#define NEO_WAIT_MS 10
DHT dht(DHT_PIN, DHT_TYPE);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEO_NUM_LEDS, NEO_PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
Serial.begin(9600);
dht.begin();
strip.begin();
strip.show();
strip.clear();
}
void fadeIn()
{
for(int i = 5; i < 255; i++)
{
colorWipe(strip.Color(i,0,0));
}
}
void fadeOut()
{
for(int i = 255; i > 5; i--)
{
colorWipe(strip.Color(i,0,0));
}
}
void colorWipe(uint32_t c)
{
for(uint16_t i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, c);
strip.show();
delay(NEO_WAIT_MS);
}
}
void loop()
{
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println(F("Failed to read from DHT sensor!"));
} else {
Serial.print(F("Temperature: "));
Serial.print(t);
Serial.print(F(" *C "));
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F(" %"));
Serial.println(F(""));
}
fadeIn();
fadeOut();
}
Basicaly I wanted to do somthing like this for temperature:
If ((t > 18) && (t < 27)) {
fadeIn(GREEN);
fadeOut(GREEN);
}else if ((t > 26) && (t < 32)){
fadeIn(YELLOW);
fadeOut(YELLOW);
}else if ((t > 32) && (t < 37)){
fadeIn(ORANGE);
fadeOut(ORANGE);
}else if ((t > 37) && (t < 45)){
fadeIn(RED);
fadeOut(RED);
}else if ((t > 0) && (t < 10)){
fadeIn(BLUE);
fadeOut(BLUE);
}
Hope someone can help me out a little bit!
Thank you as always! ![]()