本节目标
掌握基于Arduino的ESP32单片机开发基础,完成简单的项目开发。
学习记录
1. Arduino开发环境搭建
学习Arduino IDE的安装与配置,了解ESP32的开发流程。
2. 基础编程练习
通过简单的LED控制实验,掌握Arduino编程基础。
3. 项目开发
基于Arduino框架,完成一个简单的ESP32呼吸灯项目。
项目代码(呼吸灯)
以下为本节呼吸灯实验代码,效果是LED亮度从暗到亮再从亮到暗循环变化。
const int LED_PIN = 1;
const int PWMFREQ = 5000;
const int PWMRES = 8;
void setup() {
// put your setup code here, to run once:
ledcAttach(LED_PIN, PWMFREQ, PWMRES);
}
void loop() {
// put your main code here, to run repeatedly:
for(int i = 0; i <= 255; i++){
ledcWrite(LED_PIN, i);
delay(10);
}
for(int i = 255; i >= 0; i--){
ledcWrite(LED_PIN, i);
delay(10);
}
}
图片展示

