数码之家

 找回密码
 立即注册
搜索
查看: 2749|回复: 32

[Arduino] 【Arduino】168种传感器模块系列实验(147)---64位WS2812点阵屏

[复制链接]
发表于 2020-2-29 16:01:32 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手试试做实验,不管成功与否,都会记录下来---小小的进步或是搞不定的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十七:64位 WS2812B 8x8 RGB 5050 LED模块 ws2812s像素点阵屏


0.jpg

打赏

参与人数 2家元 +35 收起 理由
复_杂 + 20 優秀文章
人艰不拆了 + 15

查看全部打赏

 楼主| 发表于 2020-2-29 16:05:08 | 显示全部楼层
WS2812B
是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。

数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。

LED具有低电压驱动,环保节能,亮度高,散射角度大,一致性好,超低功率,超长寿命等优点。将控制电路集成于LED上面,电路变得更加简单,体积小,安装更加简便。
01 (1).jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-29 16:17:21 | 显示全部楼层
02.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-29 16:44:40 | 显示全部楼层
04.jpg


回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-29 16:46:53 | 显示全部楼层
04-1.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-29 16:48:07 | 显示全部楼层
04-2.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 08:52:45 | 显示全部楼层
03-.jpg

WS2812B主要特点
智能反接保护,电源反接不会损坏IC。
IC控制电路与LED点光源公用一个电源。
控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个完整的外控像素点。
内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加。
内置上电复位和掉电复位电路。
每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s。
串行级联接口,能通过一根信号线完成数据的接收与解码。
任意两点传传输距离在不超过5米时无需增加任何电路。
当刷新速率30帧/秒时,级联数不小于1024点。
数据发送速度可达800Kbps。
光的颜色高度一致,性价比高。

主要应用领域
LED全彩发光字灯串,LED全彩模组, LED全彩软灯条硬灯条,LED护栏管。
LED点光源,LED像素屏,LED异形屏,各种电子产品,电器设备跑马灯。

回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 09:12:21 | 显示全部楼层
06.jpg

名称:WS2812全彩矩阵LED模块(64位灯珠)
尺寸:6.5*6.5cm
芯片:WS2812B(内置于LED)
LED:5050封装RGB全彩高亮
电压:5V
端口:数字
平台:Arduino 单片机
控制方式:内置控制芯片,只需一个IO口即可控制

回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 09:22:17 | 显示全部楼层
模块电原理图

07.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 09:33:59 | 显示全部楼层
实验涉及到的几个WS2812B相关库
安装FastLED库,工具—管理库—搜索FastLED—安装
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafr ... ibrary-installation

09 (1).jpg

回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 09:40:35 | 显示全部楼层
08.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 09:45:09 | 显示全部楼层

  程序之一:简单蓝色流水灯
  实验接线
  Module    UNO
  VCC —— 3.3V(希望电流小一些)
  GND —— GND
  DI  ——  D6


  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  4.   安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
  5.   安装Adafruit_NeoPixel库,
  6.   下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之一:简单蓝色流水灯
  8.   实验接线
  9.   Module    UNO
  10.   VCC —— 3.3V
  11.   GND —— GND
  12.   DI  ——  D6
  13. */

  14. #include <Adafruit_NeoPixel.h>
  15. #ifdef __AVR__
  16. #include <avr/power.h> //16兆赫Adafruit饰品所需
  17. #endif

  18. // Arduino上的哪个插脚与NeoPixels相连?
  19. #define PIN        6

  20. // Arduino上有多少个LED?
  21. #define NUMPIXELS 64

  22. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

  23. #define DELAYVAL 30 //像素之间暂停的时间(毫秒)

  24. void setup() {
  25. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  26.   clock_prescale_set(clock_div_1);

  27. #endif
  28.   // 特定代码结束

  29.   pixels.begin(); // 初始化neopxel strip对象(必需)
  30. }

  31. void loop() {
  32.   pixels.clear(); //将所有像素颜色设置为“关闭”

  33.   //一串中的第一个新混合物是0,第二个是1,一直往上
  34.   //像素数减1
  35.   for (int i = 0; i < NUMPIXELS; i++) { // 对于每个像素......

  36.     //Color()接受RGB值,从0,0,0到255,255,255
  37.     //这里我们使用的是中等明亮的蓝色:
  38.     pixels.setPixelColor(i, pixels.Color(0, 0, 150));

  39.     pixels.show();   // 将更新的像素颜色发送到硬件

  40.     delay(DELAYVAL); // 在下一个通过循环之前暂停
  41.   }
  42. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 09:50:51 | 显示全部楼层
10.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 10:03:21 | 显示全部楼层
程序之二:粉色单灯流水灯

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  4.   安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
  5.   安装Adafruit_NeoPixel库,
  6.   下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之二:粉色单灯流水灯
  8.   实验接线
  9.   Module    UNO
  10.   VCC —— 3.3V
  11.   GND —— GND
  12.   DI  ——  D6
  13. */

  14. #include <Adafruit_NeoPixel.h>

  15. #define PIN 6
  16. #define MAX_LED 64

  17. #define ADD true
  18. #define SUB false

  19. int val = 0;
  20. boolean stat = ADD;

  21. Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );

  22. void setup()
  23. {
  24.   strip.begin();           //初始化Adafruit_NeoPixel;
  25.   strip.show();           //显示所有LED为关状态;
  26. }

  27. void loop()
  28. {
  29.   uint8_t i,a=0;                                       
  30.   uint32_t color = strip.Color(0, 150, 150);         //选择所显示的颜色
  31.   while(a<65)
  32.   {
  33.       for(i=0;i<64;i++)
  34.       {
  35.         if(i==a) strip.setPixelColor(i, color);     //第几个LED点亮;
  36.         else strip.setPixelColor(i, 0);             //使其他LED全灭;
  37.       }
  38.        strip.show();                                //是LED显示所选的颜色;
  39.        delay(50);                                   //延时50ms;
  40.        a++;                                         
  41.   }
  42. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 10:09:53 | 显示全部楼层

程序之三:四色交替流水灯

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  4.   安装FastLED库,工具—管理库—搜索FastLED—安装

  5.   程序之三:四色交替流水灯
  6.   实验接线
  7.   Module    UNO
  8.   VCC —— 3.3V
  9.   GND —— GND
  10.   DI  ——  D6
  11. */

  12. #include <FastLED.h>
  13. #define LED_PIN     6
  14. #define NUM_LEDS    64
  15. CRGB leds[NUM_LEDS];

  16. void setup() {
  17.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  18. }
  19. void loop() {
  20.   for (int i = 0; i <= 63; i++) {
  21.     leds[i] = CRGB ( 0, 0, 200);
  22.     FastLED.show();
  23.     delay(33);
  24.   }
  25.   for (int i = 63; i >= 0; i--) {
  26.     leds[i] = CRGB ( 89, 0, 0);
  27.     FastLED.show();
  28.     delay(33);
  29.   }
  30.   for (int i = 0; i <= 63; i++) {
  31.     leds[i] = CRGB ( 0, 89, 0);
  32.     FastLED.show();
  33.     delay(33);
  34.   }
  35.    for (int i = 63; i >= 0; i--) {
  36.     leds[i] = CRGB ( 89, 0, 200);
  37.     FastLED.show();
  38.     delay(33);
  39.   }
  40. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 10:12:47 | 显示全部楼层
11.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 10:35:09 | 显示全部楼层
程序之四:黑客帝国绿色流水灯

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  4.   安装FastLED库,工具—管理库—搜索FastLED—安装
  5.   安装Adafruit_NeoPixel库,
  6.   下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之四:黑客帝国绿色流水灯
  8.   实验接线
  9.   Module    UNO
  10.   VCC —— 3.3V
  11.   GND —— GND
  12.   DI  ——  D6
  13. */

  14. #include <Adafruit_NeoPixel.h>
  15. #define PIN 6
  16. #define MAX_LED 64

  17. #define ADD true
  18. #define SUB false

  19. int val = 0;
  20. boolean stat = ADD;

  21. Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );

  22. void setup()
  23. {
  24.   strip.begin();
  25.   strip.show();
  26. }

  27. void loop()
  28. {
  29.   uint8_t i, a = 0;
  30.   uint32_t color = strip.Color(190, 50, 0);
  31.   while (a < 65)
  32.   {
  33.     for (i = 0; i < 64; i++)
  34.     {
  35.       if (i == a) strip.setPixelColor(i, color);
  36.       else strip.setPixelColor(i, 0);
  37.     }
  38.     strip.show();
  39.     delay(25);
  40.     a++;
  41. }
  42. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 10:44:32 | 显示全部楼层
程序之五:RGB传输测试满屏变幻彩灯
  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  4.   安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
  5.   安装Adafruit_NeoPixel库,
  6.   下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之五:RGB传输测试满屏变幻彩灯
  8.   实验接线
  9.   Module    UNO
  10.   VCC —— 3.3V
  11.   GND —— GND
  12.   DI  ——  D6
  13. */


  14. #include <Adafruit_NeoPixel.h>
  15. #ifdef __AVR__
  16. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  17. #endif

  18. // Which pin on the Arduino is connected to the NeoPixels?
  19. // On a Trinket or Gemma we suggest changing this to 1:
  20. #define LED_PIN     6

  21. // How many NeoPixels are attached to the Arduino?
  22. #define LED_COUNT  60

  23. // NeoPixel brightness, 0 (min) to 255 (max)
  24. #define BRIGHTNESS 50

  25. // Declare our NeoPixel strip object:
  26. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
  27. // Argument 1 = Number of pixels in NeoPixel strip
  28. // Argument 2 = Arduino pin number (most are valid)
  29. // Argument 3 = Pixel type flags, add together as needed:
  30. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  31. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  32. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  33. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  34. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

  35. void setup() {
  36.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  37.   // Any other board, you can remove this part (but no harm leaving it):
  38. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  39.   clock_prescale_set(clock_div_1);
  40. #endif
  41.   // END of Trinket-specific code.

  42.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  43.   strip.show();            // Turn OFF all pixels ASAP
  44.   strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  45. }

  46. void loop() {
  47.   // Fill along the length of the strip in various colors...
  48.   colorWipe(strip.Color(255,   0,   0)     , 50); // Red
  49.   colorWipe(strip.Color(  0, 255,   0)     , 50); // Green
  50.   colorWipe(strip.Color(  0,   0, 255)     , 50); // Blue
  51.   colorWipe(strip.Color(  0,   0,   0, 255), 50); // True white (not RGB white)

  52.   whiteOverRainbow(75, 5);

  53.   pulseWhite(5);

  54.   rainbowFade2White(3, 3, 1);
  55. }

  56. // Fill strip pixels one after another with a color. Strip is NOT cleared
  57. // first; anything there will be covered pixel by pixel. Pass in color
  58. // (as a single 'packed' 32-bit value, which you can get by calling
  59. // strip.Color(red, green, blue) as shown in the loop() function above),
  60. // and a delay time (in milliseconds) between pixels.
  61. void colorWipe(uint32_t color, int wait) {
  62.   for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  63.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  64.     strip.show();                          //  Update strip to match
  65.     delay(wait);                           //  Pause for a moment
  66.   }
  67. }

  68. void whiteOverRainbow(int whiteSpeed, int whiteLength) {

  69.   if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;

  70.   int      head          = whiteLength - 1;
  71.   int      tail          = 0;
  72.   int      loops         = 3;
  73.   int      loopNum       = 0;
  74.   uint32_t lastTime      = millis();
  75.   uint32_t firstPixelHue = 0;

  76.   for(;;) { // Repeat forever (or until a 'break' or 'return')
  77.     for(int i=0; i<strip.numPixels(); i++) {  // For each pixel in strip...
  78.       if(((i >= tail) && (i <= head)) ||      //  If between head & tail...
  79.          ((tail > head) && ((i >= tail) || (i <= head)))) {
  80.         strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
  81.       } else {                                             // else set rainbow
  82.         int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  83.         strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  84.       }
  85.     }

  86.     strip.show(); // Update strip with new contents
  87.     // There's no delay here, it just runs full-tilt until the timer and
  88.     // counter combination below runs out.

  89.     firstPixelHue += 40; // Advance just a little along the color wheel

  90.     if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
  91.       if(++head >= strip.numPixels()) {      // Advance head, wrap around
  92.         head = 0;
  93.         if(++loopNum >= loops) return;
  94.       }
  95.       if(++tail >= strip.numPixels()) {      // Advance tail, wrap around
  96.         tail = 0;
  97.       }
  98.       lastTime = millis();                   // Save time of last movement
  99.     }
  100.   }
  101. }

  102. void pulseWhite(uint8_t wait) {
  103.   for(int j=0; j<256; j++) { // Ramp up from 0 to 255
  104.     // Fill entire strip with white at gamma-corrected brightness level 'j':
  105.     strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  106.     strip.show();
  107.     delay(wait);
  108.   }

  109.   for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
  110.     strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  111.     strip.show();
  112.     delay(wait);
  113.   }
  114. }

  115. void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
  116.   int fadeVal=0, fadeMax=100;

  117.   // Hue of first pixel runs 'rainbowLoops' complete loops through the color
  118.   // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
  119.   // just count from 0 to rainbowLoops*65536, using steps of 256 so we
  120.   // advance around the wheel at a decent clip.
  121.   for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
  122.     firstPixelHue += 256) {

  123.     for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

  124.       // Offset pixel hue by an amount to make one full revolution of the
  125.       // color wheel (range of 65536) along the length of the strip
  126.       // (strip.numPixels() steps):
  127.       uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());

  128.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  129.       // optionally add saturation and value (brightness) (each 0 to 255).
  130.       // Here we're using just the three-argument variant, though the
  131.       // second value (saturation) is a constant 255.
  132.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
  133.         255 * fadeVal / fadeMax)));
  134.     }

  135.     strip.show();
  136.     delay(wait);

  137.     if(firstPixelHue < 65536) {                              // First loop,
  138.       if(fadeVal < fadeMax) fadeVal++;                       // fade in
  139.     } else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
  140.       if(fadeVal > 0) fadeVal--;                             // fade out
  141.     } else {
  142.       fadeVal = fadeMax; // Interim loop, make sure fade is at max
  143.     }
  144.   }

  145.   for(int k=0; k<whiteLoops; k++) {
  146.     for(int j=0; j<256; j++) { // Ramp up 0 to 255
  147.       // Fill entire strip with white at gamma-corrected brightness level 'j':
  148.       strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  149.       strip.show();
  150.     }
  151.     delay(1000); // Pause 1 second
  152.     for(int j=255; j>=0; j--) { // Ramp down 255 to 0
  153.       strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  154.       strip.show();
  155.     }
  156.   }

  157.   delay(500); // Pause 1/2 second
  158. }
复制代码





回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 11:16:24 | 显示全部楼层
程序之五:RGB传输测试满屏变幻彩灯 视频(52秒)

链接:https://v.youku.com/v_show/id_XNDU2ODQ2MDI0NA==.html
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-1 11:30:03 | 显示全部楼层
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
  安装Adafruit_NeoPixel库,
  下载https://learn.adafruit.com/adafr ... ibrary-installation

  程序之六:复合流水彩虹灯
  实验接线
  Module    UNO
  VCC —— 3.3V
  GND —— GND
  DI  ——  D6

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
  4.   安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
  5.   安装Adafruit_NeoPixel库,
  6.   下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之六:复合流水彩虹灯
  8.   实验接线
  9.   Module    UNO
  10.   VCC —— 3.3V
  11.   GND —— GND
  12.   DI  ——  D6
  13. */

  14. #include <Adafruit_NeoPixel.h>

  15. #define PIN 6
  16. #define BRIGHTNESS 64

  17. Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);

  18. void setup() {
  19.   strip.setBrightness(BRIGHTNESS);
  20.   strip.begin();
  21.   strip.show();
  22. }

  23. void loop() {
  24.   colorWipe(strip.Color(150, 0, 0), 50); // Red
  25.   colorWipe(strip.Color(0, 150, 0), 50); // Green
  26.   colorWipe(strip.Color(0, 0, 150), 50); // Blue
  27.   colorWipe(strip.Color(150, 150, 150), 50); // BlueWite
  28.   rainbowCycle(1);

  29. }

  30. void colorWipe(uint32_t c, uint8_t wait) {
  31.   for (uint16_t i = 0; i < strip.numPixels(); i++) {
  32.     strip.setPixelColor(i, c);
  33.     strip.show();
  34.     delay(wait);
  35.   }
  36. }

  37. void rainbow(uint8_t wait) {
  38.   uint16_t i, j;
  39.   for (j = 0; j < 256; j++) {
  40.     for (i = 0; i < strip.numPixels(); i++) {
  41.       strip.setPixelColor(i, Wheel((i + j) & 255 ));
  42.     }
  43.     strip.show();
  44.     delay(wait);
  45.   }
  46. }

  47. void rainbowCycle(uint8_t wait) {
  48.   uint16_t i, j;
  49.   for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
  50.     for (i = 0; i < strip.numPixels(); i++) {
  51.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  52.     }
  53.     strip.show();
  54.     delay(wait);
  55.   }
  56. }

  57. uint32_t Wheel(byte WheelPos) {
  58.   if (WheelPos < 85) {
  59.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  60.   } else if (WheelPos < 170) {
  61.     WheelPos -= 85;
  62.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  63.   } else {
  64.     WheelPos -= 170;
  65.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  66.   }
  67. }
复制代码


回复 支持 反对

使用道具 举报

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

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-4-29 20:52 , Processed in 0.280801 second(s), 16 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

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