Nodemcu 驱动WS2812点灯红色变绿色的原因及解决

news/2024/7/4 1:15:01

初次接触FastLed,先点灯。开发环境VSCODE PlatformIO 。

直接使用FastLed的示例blink程序,略有修改DATA_PIN D1,注释掉CLOCK_PIN。

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 1

// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN D1
#define BRIGHTNESS 8
// #define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
    // Uncomment/edit one of the following lines for your leds arrangement.
    // ## Clockless types ##
    
    FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
 FastLED.setBrightness( BRIGHTNESS );    
}

void loop() { 
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}

代码是红色,但运行效果是绿色灯闪烁,后搜索bing 发现其他人有同样问题,就是颜色相反,红色变绿色。

国外网友遇到的问题及解决

总结下来是颜色格式的问题,我买的WS2812模块是GRB格式。其实示例的注释也提醒了GRB是典型格式。

修改的源码中的为:

 FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical

完整源码:

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 1

// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN D1
#define BRIGHTNESS 8
// #define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
    // Uncomment/edit one of the following lines for your leds arrangement.
    // ## Clockless types ##
    
    FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical   
FastLED.setBrightness( BRIGHTNESS ); 
}

void loop() { 
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}

工程配置:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps = fastled/FastLED@^3.5.0
monitor_speed = 115200 ;monitor baud
upload_speed = 921600  ;upload baud


http://www.niftyadmin.cn/n/3540326.html

相关文章

windows在与time.windows.com进行同步时出错

windows在与time.windows.com进行同步时出错 CreateTime--2017年6月29日10:28:16Author:Marydon 参考地址&#xff1a;http://www.jb51.net/os/windows/274285.html 解决方案&#xff1a; UpdateTime--2017年7月3日09:21:58 将Windows Time设置为开机自启动 WINR-->service.…

如何给Infopath表单保存时自动命名和自动关闭

这是课程中的一个小问题和例子&#xff0c;分享出来给更多朋友参考 问题&#xff1a; 默认情况下&#xff0c;我们在SharePoint中通过Forms Service填写Infopath表单的时候&#xff0c;当我们点击了“Save”菜单项&#xff0c;会弹出一个对话框来&#xff0c;这里我们需要输入一…

《向量数据库指南》——什么是比较 Embedding?

目录 比较 Embedding 准备工作 示例 0:Marlon Brando 示例 1:国王与王后 示例 2:Apple,水果还是公司 欢迎回到向量数据库 101 系列教程。 之前的教程中,我们介绍了非结构化数据、向量数据库和 Milvus——全球最受欢迎的开源向量数据库。我们还简单介绍了 Embedding …

Arduino Modbus 笔记(1)

开发环境&#xff1a;arduino IDE 2.0.3 库下载链接 库测试&#xff0c;选用库自带的simple_slave例程 源码 /*** Modbus slave example 1:* The purpose of this example is to link a data array* from the Arduino to an external device.** Recommended Modbus Maste…

系统调用函数

转&#xff1a;http://blog.csdn.net/sailor_8318/article/details/2906968 一、进程控制&#xff1a; fork 创建一个新进程 clone 按指定条件创建子进程 execve 运行可执行文件 exit 中止进程 _exit 立即中止当前进程 getdtablesize 进程所能打开的最大文件数 ge…

Flex中的正则表达式(一)

Flex中的正则表达式&#xff08;1&#xff09; (2010-04-09 11:17:11) 转载标签&#xff1a; it 分类&#xff1a; Flex1.基本语法 . 匹配除换行符"\n"外的任意单个字符。 * 匹配前面正则表达式的零次或多次出现。 eg:trace("This Book Is Good Boooook BoxB…

autotools时出现的错误

原文&#xff1a;https://blog.csdn.net/w2008824/article/details/27242491 automake提示错误configure.ac:5: installing ./install-sh; error while making link configure.ac:5: installing ./install-sh; error while making link: 不允许的操作 configure.ac:5: insta…

Joomla安装MySql支持问题解决

安装版本为Joomla! 1.7.3 Stable,安装过程第二步第四项“MySQL 支持 否”&#xff0c;无法继续&#xff0c;解决方法如下&#xff1a;打开PHP文件夹修改php.ini第542行&#xff08;PHP为php-5.2.17-Win32-VC6-x86.zip解压安装&#xff09;&#xff0c;将前面分号去掉&#xff0…