在platformIO点亮ESP32S3板载RGB灯


建项目

新建platformIO项目,配置如下,Board先选dev module,进去之后再改

项目创建完成以后将platformio.ini修改为以下内容

点击查看代码
[env:esp32dev]
platform = https://github.com/tasmota/platform-espressif32/archive/refs/heads/IDF44/ESP32-S3.zip
board = esp32-s3-devkitc-1
framework = arduino

写测试代码

查原理图可知板载RGB有1个,引脚分别为IO5、IO6和IO7

将以下代码填入至main.cpp

点击查看代码
/*
 * @Author: Dapenson
 * @Date: 2022-04-14 11:14:04
 * @LastEditors: Dapenson
 * @LastEditTime: 2022-04-14 11:20:48
 * @FilePath: \S3-rgb-demo\src\main.cpp
 * @Description:
 *
 * Copyright (c) 2022 by Dapenson, All Rights Reserved.
 */
#include <Arduino.h>

void light_rgb(int r, int g, int b);

// ============================================================
void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop()
{
  light_rgb(255, 0, 0);
  delay(1000);
  light_rgb(0, 255, 0);
  delay(1000);
  light_rgb(0, 0, 255);
  delay(1000);
}

// 点亮rgb灯
void light_rgb(int r, int g, int b)
{
  analogWrite(5, r);
  analogWrite(6, g);
  analogWrite(7, b);
}

上传测试

点击上传按钮或按Ctrl+Alt+u快捷键进行上传
上传后终端会显示下载资源包和进度

等待上传完成后重启开发板即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM