news 2026/2/21 8:39:35

ESP32-S3(3) : 点亮WS2812 RGB

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ESP32-S3(3) : 点亮WS2812 RGB

1.说明

开发框架 : ESP-IDF, 版本: 5.5.0

开发版图片(图中左边typec接口上面一点的白色小方块就是WS2812 RGB) :

2.代码

main/CMakeLists.txt

# 主程序组件 idf_component_register(SRCS "main.c" INCLUDE_DIRS ".")

CMakeLists.txt

# The following five lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(0_kai_fa_ban)

main/main.c

rmt.h过时了, 但是不影响功能

#include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/rmt.h" #include "esp_log.h" static const char *TAG = "WS2812"; #define WS2812_GPIO_PIN GPIO_NUM_48 #define LED_NUM 1 #define RMT_TX_CHANNEL RMT_CHANNEL_0 // WS2812 timing parameters (in nanoseconds) #define T0H 350 // 0 bit high time #define T0L 900 // 0 bit low time #define T1H 900 // 1 bit high time #define T1L 350 // 1 bit low time #define RESET 50000 // Reset time // Convert time to RMT ticks (80MHz / 4 = 20MHz, 1 tick = 50ns) #define NS_TO_TICKS(ns) ((ns) / 50) void ws2812_init(void) { rmt_config_t config = RMT_DEFAULT_CONFIG_TX(WS2812_GPIO_PIN, RMT_TX_CHANNEL); config.clk_div = 4; // 80MHz / 4 = 20MHz config.mem_block_num = 1; config.tx_config.loop_en = false; config.tx_config.carrier_en = false; config.tx_config.idle_output_en = true; config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW; ESP_ERROR_CHECK(rmt_config(&config)); ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); ESP_LOGI(TAG, "WS2812 initialized on GPIO %d", WS2812_GPIO_PIN); } void set_led_color(uint8_t red, uint8_t green, uint8_t blue) { uint8_t color[3] = {green, red, blue}; // WS2812 uses GRB order rmt_item32_t items[24]; // 3 bytes * 8 bits // Convert each bit to RMT items for (int i = 0; i < 3; i++) { for (int j = 0; j < 8; j++) { int bit_index = (i * 8) + j; if (color[i] & (1 << (7 - j))) { // Bit 1 items[bit_index].level0 = 1; items[bit_index].duration0 = NS_TO_TICKS(T1H); items[bit_index].level1 = 0; items[bit_index].duration1 = NS_TO_TICKS(T1L); } else { // Bit 0 items[bit_index].level0 = 1; items[bit_index].duration0 = NS_TO_TICKS(T0H); items[bit_index].level1 = 0; items[bit_index].duration1 = NS_TO_TICKS(T0L); } } } // Send data ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, items, 24, true)); // Reset vTaskDelay(pdMS_TO_TICKS(1)); } void app_main(void) { ESP_LOGI(TAG, "Starting WS2812 Demo"); ws2812_init(); vTaskDelay(pdMS_TO_TICKS(1000)); while (1) { ESP_LOGI(TAG, "Red"); set_led_color(255, 0, 0); vTaskDelay(pdMS_TO_TICKS(1000)); ESP_LOGI(TAG, "Green"); set_led_color(0, 255, 0); vTaskDelay(pdMS_TO_TICKS(1000)); ESP_LOGI(TAG, "Blue"); set_led_color(0, 0, 255); vTaskDelay(pdMS_TO_TICKS(1000)); ESP_LOGI(TAG, "White"); set_led_color(255, 255, 255); vTaskDelay(pdMS_TO_TICKS(1000)); ESP_LOGI(TAG, "Off"); set_led_color(0, 0, 0); vTaskDelay(pdMS_TO_TICKS(1000)); } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/15 20:01:02

腾讯混元A13B-FP8开源:130亿参数实现800亿级性能突破

腾讯正式宣布开源混元大模型的FP8量化版本——Hunyuan-A13B-Instruct-FP8&#xff0c;该模型凭借创新的混合专家架构和高效量化技术&#xff0c;在仅激活130亿参数的情况下实现了传统800亿级模型的性能表现&#xff0c;为AI领域的能效革命带来重大突破。 【免费下载链接】Hunyu…

作者头像 李华
网站建设 2026/2/12 4:16:34

音乐解锁终极指南:轻松解密你的加密音乐收藏

音乐解锁终极指南&#xff1a;轻松解密你的加密音乐收藏 【免费下载链接】unlock-music 在浏览器中解锁加密的音乐文件。原仓库&#xff1a; 1. https://github.com/unlock-music/unlock-music &#xff1b;2. https://git.unlock-music.dev/um/web 项目地址: https://gitcod…

作者头像 李华
网站建设 2026/2/21 18:04:11

Fun-ASR系统设置详解:批处理大小、最大长度等参数调优指南

Fun-ASR系统设置详解&#xff1a;批处理大小、最大长度等参数调优指南 在智能语音应用日益普及的今天&#xff0c;从会议纪要自动生成到客服录音分析&#xff0c;自动语音识别&#xff08;ASR&#xff09;已不再是实验室里的概念&#xff0c;而是企业数字化流程中的关键一环。然…

作者头像 李华
网站建设 2026/2/19 18:25:19

网易云音乐批量下载工具使用指南

网易云音乐批量下载工具使用指南 【免费下载链接】netease-cloud-music-dl Netease cloud music song downloader, with full ID3 metadata, eg: front cover image, artist name, album name, song title and so on. 项目地址: https://gitcode.com/gh_mirrors/ne/netease-c…

作者头像 李华
网站建设 2026/2/21 6:21:10

B站缓存视频永久保存方案:m4s无损转MP4完整教程

还在为B站缓存视频无法跨设备播放而烦恼吗&#xff1f;那些珍贵的m4s格式文件&#xff0c;其实只需要简单几步就能变成通用的MP4格式&#xff0c;实现真正的永久保存和无缝播放。 【免费下载链接】m4s-converter 将bilibili缓存的m4s转成mp4(读PC端缓存目录) 项目地址: https…

作者头像 李华
网站建设 2026/2/22 6:09:58

最大长度限制防止超长序列引发OOM错误,系统默认值合理

最大长度限制防止超长序列引发OOM错误&#xff0c;系统默认值合理 在语音识别系统的实际部署中&#xff0c;一个看似简单的参数设置——“最大输入长度”&#xff0c;往往决定了整个服务的稳定性与可用性。尤其是在基于Transformer架构的大规模ASR模型&#xff08;如Fun-ASR&am…

作者头像 李华