赞
踩
新手必经之路,点亮开发板上的LED灯。
根据原理图确定开发板上的LED灯连接在哪个GPIO口上,例如我这个就是在GPIO2口上连接。
注:ESP系列原理图可以去安信可
找对应的型号下载观看
根据原理图可知LED连接3.3V电源,因此GPIO口输出为低时LED点亮,输出为高电平时LED等熄灭。
- #define PIN 2 //定义GPIO口,根据原理图修改
- void setup() {
- // put your setup code here, to run once:
- pinMode(PIN, OUTPUT); //设置该GPIO口为输出
- }
-
- void loop() {
- // put your main code here, to run repeatedly:
- digitalWrite(PIN, HIGH);//输出高电平
- delay(1000);//延时
- digitalWrite(PIN, LOW);//输出低电平
- delay(1000);//延时
- }
编译下载后可以看到开发板LED开始规律闪烁。
添加串口打印:
- #define PIN 2
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600); // 启动串口通讯,设置波特率
- pinMode(PIN, OUTPUT);//设置该GPIO口为输出
- }
-
- void loop() {
- // put your main code here, to run repeatedly:
- digitalWrite(PIN, HIGH);//输出高电平
- Serial.println("LED is off");
- delay(1000);//延时
- digitalWrite(PIN, LOW);//输出低电平
- Serial.println("LED is on");
- delay(1000);//延时
- }

这时打开串口监视器就会看到打印的数据:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。