初学者练习作品,不难但是还是要点心思。
硬件包括:面包板,esp32,DHT22温度传感器,SSD1306屏幕,DS1307时钟模块。
以下是模拟运行的效果。
运行需要的库和代码:
#include "DHTesp.h"
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_SSD1306.h>
RTC_DS1307 rtc;
const char* daysOfTheWeek[7] = {"Sun*7", "Mon*1", "Tue*2", "Wed*3", "Thu*4", "Fri*5", "Sat*6"};
const int DHT_PIN = 15;
#define SCREEN_WIDTH 128 // OLED 显示宽度(以像素为单位)
#define SCREEN_HEIGHT 64 // OLED 显示高度(以像素为单位)
DHTesp dhtSensor;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void printLocalTime() { //初始化DS1307模块
if (!rtc.begin()) {
Serial.println("RTC connection failed.");
return;
}
if (!rtc.isrunning()) {
Serial.println("RTC is not running.");
return;
}
DateTime now = rtc.now();
Serial.print(daysOfTheWeek[now.d