/**
* 模块管脚 <--> 开发板管脚 <--> 外设管脚
* GPIO16 D0 LED
* GPIO0 D3 FLASH
*/
#define LED_PIN D0
#define FLASH_KEY D3
void setup() {
// put your setup code here, to run once:
// 设置LED管脚为输出模式
pinMode(LED_PIN, OUTPUT);
// 设置FLASH按钮管脚为输入模式
pinMode(FLASH_KEY, INPUT);
// 初始化时输出低电位(最亮)
digitalWrite(LED_PIN, 0);
}
void loop() {
// put your main code here, to run repeatedly:
// 读取按钮值
int Key = digitalRead(FLASH_KEY);
// 判断按钮状态
if(Key == 0)
{
// 按钮为低电位,点亮LED
digitalWrite(LED_PIN, LOW);
}
else
{
// 按钮为高电位,熄灭LED
digitalWrite(LED_PIN, HIGH);
}
// 延时500毫秒
delay(500);
}
转载:https://blog.csdn.net/lee198717/article/details/102147532
查看评论