Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <M5StickC.h>
  2. #include <DHT.h>
  3.  
  4.  
  5.  
  6. #define DHTPIN 26 // what pin we're connected to
  7. #define TFT_GREY 0x5AEB
  8. // Uncomment whatever type you're using!
  9. #define DHTTYPE DHT11 // DHT 11
  10. //#define DHTTYPE DHT22 // DHT 22 (AM2302)
  11. //#define DHTTYPE DHT21 // DHT 21 (AM2301)
  12.  
  13. // Initialize DHT sensor for normal 16mhz Arduino
  14. DHT dht(DHTPIN, DHTTYPE);
  15.  
  16. void setup() {
  17. M5.begin();
  18. M5.Lcd.setRotation(3);
  19. Serial.begin(9600);
  20. Serial.println("DHTxx test!");
  21.  
  22. dht.begin();
  23. }
  24.  
  25. void loop() {
  26.     // Wait a few seconds between measurements.
  27. delay(2000);
  28. M5.Lcd.fillScreen(TFT_GREY);
  29. // Reading temperature or humidity takes about 250 milliseconds!
  30. // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  31. float h = dht.readHumidity();
  32. // Read temperature as Celsius
  33. float t = dht.readTemperature();
  34. // Read temperature as Fahrenheit
  35. float f = dht.readTemperature(true);
  36.  
  37.  
  38. M5.Lcd.setCursor(0, 0, 2);
  39. M5.Lcd.setTextColor(TFT_WHITE,TFT_BLACK);
  40. M5.Lcd.setTextSize(1);
  41. // Compute heat index
  42. // Must send in temp in Fahrenheit!
  43. float hi = dht.computeHeatIndex(f, h);
  44. M5.Lcd.println("");
  45.  
  46. M5.Lcd.print("Humidity: ");
  47. M5.Lcd.println(h);
  48. Serial.print("Humidity: ");
  49. Serial.print(h);
  50. Serial.print(" %\t");
  51. M5.Lcd.setTextColor(TFT_YELLOW,TFT_BLACK);
  52. M5.Lcd.setTextFont(2);
  53. M5.Lcd.print("Temperature: ");
  54. M5.Lcd.println(t);
  55. Serial.print("Temperature: ");
  56. Serial.print(t);
  57. Serial.print(" *C ");
  58. Serial.print(f);
  59. Serial.print(" *F\t");
  60. M5.Lcd.setTextColor(TFT_GREEN,TFT_BLACK);
  61. M5.Lcd.setTextFont(2);
  62. M5.Lcd.print("Heat index: ");
  63. M5.Lcd.println(hi);
  64. Serial.print("Heat index: ");
  65. Serial.print(hi);
  66. Serial.println(" *F");
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement