找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1392|回复: 4
打印 上一主题 下一主题
收起左侧

ARDUINO点亮WS2812问题,如何延时1秒后再点亮余下的10颗WS2812,不断循环

[复制链接]
跳转到指定楼层
楼主
ID:143767 发表于 2022-1-25 16:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
以下程序是点亮10颗任意颜色WS2812,我想延时1秒左右后再点亮余下的10颗WS2812,不断循环,程序该怎样修改呢?麻烦大佬帮忙指点一下,谢谢。

#include <Adafruit_NeoPixel.h>

/*
  【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
  实验一百三十一:24位 WS2812 5050 RGB LED 内置全彩驱动彩灯 圆形开发板
  项目三:使用红色、绿色和蓝色三种参数将任何LED设置为任何颜色
  Module      UNO
  VCC   ——   5V
  GND  ——   GND
  DI    ——   D6
*/

#include <FastLED.h>
#define LED_PIN     6
#define NUM_LEDS    24
CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

}
void loop() {

  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  delay(500);  
  leds[1] = CRGB(0, 255, 0);
  FastLED.show();
  delay(500);
  leds[2] = CRGB(0, 0, 255);
  FastLED.show();
  delay(500);
  leds[3] = CRGB(150, 0, 255);
  FastLED.show();
  delay(500);
  leds[4] = CRGB(255, 200, 20);
  FastLED.show();
  delay(500);
  leds[5] = CRGB(85, 60, 180);
  FastLED.show();
  delay(500);
  leds[6] = CRGB(50, 255, 20);
  FastLED.show();

delay(500);

  leds[7] = CRGB(255, 0, 0);
  FastLED.show();
  delay(500);  
  leds[8] = CRGB(0, 255, 0);
  FastLED.show();
  delay(500);
  leds[9] = CRGB(0, 0, 255);
  FastLED.show();
  delay(500);
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:161164 发表于 2022-1-25 21:23 | 只看该作者
同一问题为什么又发多一次贴子?
"不断循环"中想要循环的是什么?
回复

使用道具 举报

板凳
ID:143767 发表于 2022-1-26 16:39 | 只看该作者
lkc8210 发表于 2022-1-25 21:23
同一问题为什么又发多一次贴子?
"不断循环"中想要循环的是什么?

就是每组不同颜色的10颗灯一起亮,然后与第二组10颗灯交替亮,一直循环下去
回复

使用道具 举报

地板
ID:161164 发表于 2022-1-26 17:41 | 只看该作者
看看这样行不?

  1. #include <Adafruit_NeoPixel.h>

  2. /*
  3.   【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
  4.   实验一百三十一:24位 WS2812 5050 RGB LED 内置全彩驱动彩灯 圆形开发板
  5.   项目三:使用红色、绿色和蓝色三种参数将任何LED设置为任何颜色
  6.   Module      UNO
  7.   VCC   ——   5V
  8.   GND  ——   GND
  9.   DI    ——   D6
  10. */

  11. #include <FastLED.h>
  12. #define LED_PIN     6
  13. #define NUM_LEDS    24

  14. CRGB leds[NUM_LEDS];
  15. void setup() {
  16.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

  17. }
  18. void loop() {

  19. unsigned int i;

  20.   leds[0] = CRGB(255, 0, 0);
  21.   FastLED.show();
  22.   delay(500);  
  23.   leds[1] = CRGB(0, 255, 0);
  24.   FastLED.show();
  25.   delay(500);
  26.   leds[2] = CRGB(0, 0, 255);
  27.   FastLED.show();
  28.   delay(500);
  29.   leds[3] = CRGB(150, 0, 255);
  30.   FastLED.show();
  31.   delay(500);
  32.   leds[4] = CRGB(255, 200, 20);
  33.   FastLED.show();
  34.   delay(500);
  35.   leds[5] = CRGB(85, 60, 180);
  36.   FastLED.show();
  37.   delay(500);
  38.   leds[6] = CRGB(50, 255, 20);
  39.   FastLED.show();
  40.   delay(500);
  41.   leds[7] = CRGB(255, 0, 0);
  42.   FastLED.show();
  43.   delay(500);  
  44.   leds[8] = CRGB(0, 255, 0);
  45.   FastLED.show();
  46.   delay(500);
  47.   leds[9] = CRGB(0, 0, 255);
  48.   FastLED.show();
  49.   delay(500);
  50.   
  51.   for(i=10;i<20;i++)
  52.   {
  53.           leds[i] = CRGB(0, 0, 0);          
  54.   }
  55.   FastLED.show();
  56.   
  57.   
  58.   delay(1000);
  59.   for(i=0;i<10;i++)
  60.   {
  61.           leds[i] = CRGB(0, 0, 0);          
  62.   }
  63.   FastLED.show();
  64.   
  65.   leds[10] = CRGB(255, 0, 0);
  66.   FastLED.show();
  67.   delay(500);  
  68.   leds[11] = CRGB(0, 255, 0);
  69.   FastLED.show();
  70.   delay(500);
  71.   leds[12] = CRGB(0, 0, 255);
  72.   FastLED.show();
  73.   delay(500);
  74.   leds[13] = CRGB(150, 0, 255);
  75.   FastLED.show();
  76.   delay(500);
  77.   leds[14] = CRGB(255, 200, 20);
  78.   FastLED.show();
  79.   delay(500);
  80.   leds[15] = CRGB(85, 60, 180);
  81.   FastLED.show();
  82.   delay(500);
  83.   leds[16] = CRGB(50, 255, 20);
  84.   FastLED.show();
  85.   delay(500);
  86.   leds[17] = CRGB(255, 0, 0);
  87.   FastLED.show();
  88.   delay(500);  
  89.   leds[18] = CRGB(0, 255, 0);
  90.   FastLED.show();
  91.   delay(500);
  92.   leds[19] = CRGB(0, 0, 255);
  93.   FastLED.show();
  94.   delay(1000);
  95.   
  96. }
复制代码
回复

使用道具 举报

5#
ID:143767 发表于 2022-1-26 18:25 | 只看该作者
lkc8210 发表于 2022-1-26 17:41
看看这样行不?

好的很感谢,我试验一下,不懂的地方再向您请教
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表