#include <WiFi.h>
#include <Wire.h>
#include <Arduino.h>
//引入驱动OLED_0.96所需的库
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // 设置OLED宽度,单位:像素
#define SCREEN_HEIGHT 64 // 设置OLED高度,单位:像素
//自定义重置引脚,虽然教程未使用,但却是Adafruit_SSD1306库文件所必需的
#define OLED_RESET 4
//接线说明:oled的SCL-16 SDA-17 舵机信号线-15 按键一侧-GND另一侧-12
//功能描述:利用esp32的WIFI功能获取实时时间,并实现倒计时的功能,倒计时结束led闪烁并且舵机以180°来回旋转,led可替换为蜂鸣器,实现“闹钟”的功能
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int positionX=0;
const char *ssid = "ESP32"; //你的网络名称
const char *password = "88888888"; //你的网络密码
const char *ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 8 * 3600;//用来修正时区的,该参数为东八区
const int daylightOffset_sec = 0;
int led=2;
int Key=12;
int Boot=0;
int state = 0;
int clk_sec=0;
int start_clk=0;
int cnt=0;
int time_up=0;
int led_state=0;
int freq = 50; // 频率(20ms周期)
int channel = 8; // 通道(高速通道(0 ~ 7)由80MHz时钟驱动,
基于ESP32的实时时钟显示
最新推荐文章于 2025-09-16 13:07:01 发布
这个项目使用ESP32通过WiFi连接获取网络时间,并在0.96英寸的OLED显示屏上显示。同时,实现了倒计时功能,当倒计时结束时,LED灯闪烁且舵机进行180°旋转,可以作为简单的闹钟装置。代码中包含了时间设置、OLED显示、舵机控制等关键部分。

最低0.47元/天 解锁文章
754

被折叠的 条评论
为什么被折叠?



