1 Star 0 Fork 3

Harry / esp32_spi_ws2812

forked from James / esp32_spi_ws2812 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ESP32芯片通过SPI控制WS2812灯带

ESP32芯片一般可以通过RMT的方式控制LED灯带,但是连接蓝牙或wifi的情况下,灯带会闪烁或不稳定,这里给出使用SPI控制灯带的方案,LED动态效果更加稳定

使用方法

第1种 将项目所有文件下载到本地,直接用ESP-IDF环境运行本项目。

第2种 复制components目录下的spi_ws2812组件到你项目中,并通过以下代码调用:

//初始化
spi_ws2812_init();

//循环
while(1){
    uint32_t tmp[]={0xFF0000,0x00FF00,0x0000FF}; //Red , Green , Blue
    setLedColorByArr(3,tmp);
    usleep(1000*1000);

    uint32_t tmp1[]={0xFFFF00,0x00FFFF,0xFF00FF}; //Yellow , Tiffany , Pink
    setLedColorByArr(3,tmp1);
    usleep(1000*1000);
}

颜色通过如 0x00FFFF 的整数来表示,对应到常用的RGB颜色 例:

红色 0xFF0000

绿色 0x00FF00

蓝色 0x0000FF

原理

WS2812的显示信号为每24位控制一个灯的显示。通过SPI数据流的每一个字节,模拟WS2812信号中的1个位,每24个字节,模拟一个灯的控制信号

其他参考

通过RMT的方式控制灯带

https://github.com/JSchaenzle/ESP32-NeoPixel-WS2812-RMT

https://github.com/FozzTexx/ws2812-demo

MIT License Copyright (c) 2020 James Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

esp32通过spi控制ws2812 展开 收起
C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/Harry_YiZu/esp32_spi_ws2812.git
git@gitee.com:Harry_YiZu/esp32_spi_ws2812.git
Harry_YiZu
esp32_spi_ws2812
esp32_spi_ws2812
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891