TA的每日心情 | 奋斗 2016-4-18 10:19 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
用小e做了个电子表,实时显示当前环境的温湿度,运行界面如下图所示:
源代码如下:- #include <Wire.h>
- #include "SSD1306.h"
- #include "dht.h""
- // Initialize the oled display for address 0x3c
- //I2C-ADD=0X3C, sda-pin=2 and sdc-pin=14
- SSD1306 oled(0x3c, 2, 14);
- #define DHT11_PIN 5
- dht DHT;
- void setup()
- {
- Serial.begin(115200);
- oled.init();
- oled.flipScreenVertically();
- }
- void loop()
- {
- String h_data = "Humi(%) : ";
- String t_data = "Temp(oC): ";
- int chk = DHT.read11(DHT11_PIN);
- switch (chk)
- {
- case DHTLIB_OK:
- h_data += String(DHT.humidity);
- t_data += String(DHT.temperature);
- break;
- case DHTLIB_ERROR_CHECKSUM:
- case DHTLIB_ERROR_TIMEOUT:
- default:
- h_data += "error";
- t_data += "error";
- break;
- }
- oled.setFont(ArialMT_Plain_16);
- oled.setTextAlignment(TEXT_ALIGN_LEFT);
- oled.drawString(0, 10, h_data);
- oled.drawString(0, 40, t_data);
- oled.display();
- oled.clear();
- delay(1000);
- }
复制代码 |
|