其他分享
首页 > 其他分享> > 合宙ESP32C3板载按钮控制板载LED

合宙ESP32C3板载按钮控制板载LED

作者:互联网

相关资料

合宙ESP32-C3资料链接


示例代码

代码功能,按下板载按钮boot切换左右LED亮灯显示

#include <Arduino.h>

const int board_btn = 9;
const int board_led_left = 12;
const int board_led_right = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(board_btn, INPUT);
  pinMode(board_led_left, OUTPUT);
  pinMode(board_led_right, OUTPUT);
}

void loop()
{
  if (digitalRead(board_btn) == HIGH)
  //默认为高电平
  {
    digitalWrite(board_led_left, HIGH);
    digitalWrite(board_led_right, LOW);
  }
  else
  // 按下按钮为低电平
  {
    digitalWrite(board_led_left, LOW);
    digitalWrite(board_led_right, HIGH);
  }
  Serial.println(digitalRead(board_btn));
  delay(200);
}

使用platform IO编译

如果使用platformIO编译,则需在platformio.ini文件中添加以下内容


[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
board_build.flash_mode = dio

标签:板载,合宙,led,digitalWrite,right,board,LED,btn,left
来源: https://www.cnblogs.com/dapenson/p/16322599.html