6376| 0
|
[项目] FireBeetle LED_Matrix滚动显示温度 |
准备以下物料清单并连接引脚:
直接上代码: [mw_shl_code=cpp,true]#include <stdio.h> #include <string.h> #include "DFRobot_HT1632C.h" #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); #if defined( ESP_PLATFORM ) || defined( Arduino_ARCH_FIREBEETLE8266 ) //FireBeetle-ESP32 FireBeetle-ESP8266 #define DATA D6 #define CS D5 #define WR D7 //#define RD D8 #else #define DATA 6 #define CS 5 #define WR 7 //#define RD 8 #endif DFRobot_HT1632C ht1632c = DFRobot_HT1632C(DATA, WR,CS); char text[2]; void setup() { Serial.begin(115200); dht.begin(); ht1632c.begin(); ht1632c.isLedOn(true); ht1632c.clearScreen(); } void loop() { delay(1000); char text2[10] = "temp:"; int h = dht.readHumidity(); int t = dht.readTemperature(); int f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Failed to read from DHT sensor!"); return; } // Compute heat index in Fahrenheit (the default) int hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) int hic = dht.computeHeatIndex(t, h, false); Serial.print("Humidity: "); Serial.print(h); Serial.print("\n"); Serial.print("Temperature: "); Serial.print(t); Serial.print(" *C "); Serial.print("\n"); //ht1632c.drawText(strcat(text1, itoa(t, text, 10)), 0, 0, FONT_8X4, FONT_8X4_END, FONT_8X4_HEIGHT); //ht1632c.writeScreen(); ht1632c.print(strcat(text2, itoa(t, text, 10)), 50); }[/mw_shl_code] 运行效果: |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed