Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <M5StickC.h>
- #include <DHT.h>
- #define DHTPIN 26 // what pin we're connected to
- #define TFT_GREY 0x5AEB
- // Uncomment whatever type you're using!
- #define DHTTYPE DHT11 // DHT 11
- //#define DHTTYPE DHT22 // DHT 22 (AM2302)
- //#define DHTTYPE DHT21 // DHT 21 (AM2301)
- // Initialize DHT sensor for normal 16mhz Arduino
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- M5.begin();
- M5.Lcd.setRotation(3);
- Serial.begin(9600);
- Serial.println("DHTxx test!");
- dht.begin();
- }
- void loop() {
- // Wait a few seconds between measurements.
- delay(2000);
- M5.Lcd.fillScreen(TFT_GREY);
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- float h = dht.readHumidity();
- // Read temperature as Celsius
- float t = dht.readTemperature();
- // Read temperature as Fahrenheit
- float f = dht.readTemperature(true);
- M5.Lcd.setCursor(0, 0, 2);
- M5.Lcd.setTextColor(TFT_WHITE,TFT_BLACK);
- M5.Lcd.setTextSize(1);
- // Compute heat index
- // Must send in temp in Fahrenheit!
- float hi = dht.computeHeatIndex(f, h);
- M5.Lcd.println("");
- M5.Lcd.print("Humidity: ");
- M5.Lcd.println(h);
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t");
- M5.Lcd.setTextColor(TFT_YELLOW,TFT_BLACK);
- M5.Lcd.setTextFont(2);
- M5.Lcd.print("Temperature: ");
- M5.Lcd.println(t);
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.print(" *C ");
- Serial.print(f);
- Serial.print(" *F\t");
- M5.Lcd.setTextColor(TFT_GREEN,TFT_BLACK);
- M5.Lcd.setTextFont(2);
- M5.Lcd.print("Heat index: ");
- M5.Lcd.println(hi);
- Serial.print("Heat index: ");
- Serial.print(hi);
- Serial.println(" *F");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement