eagler8 发表于 2022-10-21 18:03

【Arduino】168种传感器系列实验(214)---8x32位全彩WS2812B屏

<div class='showpostmsg'><p>37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手试试多做实验,不管成功与否,都会记录下来&mdash;&mdash;小小的进步或是搞不掂的问题,希望能够抛砖引玉。<br style="overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal; background-color:#ffffff" />
<br style="overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal; background-color:#ffffff" />
<strong style="overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal; background-color:#ffffff">【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)</strong><br style="overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal; background-color:#ffffff" />
<strong style="overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal; background-color:#ffffff">实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 可编程硬屏模块</strong></p>

<p>&nbsp;</p>

<p></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

eagler8 发表于 2022-10-21 18:11

<p></p>

eagler8 发表于 2022-10-21 18:12

<p>WS2812B<br />
是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-21 18:16

<table style="overflow-wrap:break-word; empty-cells:show; border-collapse:collapse; table-layout:fixed; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal; background-color:#ffffff">
        <tbody style="overflow-wrap:break-word">
                <tr>
                        <td id="postmessage_664169" style="background-color:#ffffff">
                        <p>WS2812B灯屏电原理参考图</p>

                        <p>&nbsp;</p>

                        <p></p>
                        </td>
                </tr>
        </tbody>
</table>

eagler8 发表于 2022-10-21 18:31

<p>实验涉及到的几个WS2812B相关库<br style=" overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal" />
安装FastLED库,工具&mdash;管理库&mdash;搜索FastLED&mdash;安装<br style=" overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal" />
安装NeoPixel库,工具&mdash;管理库&mdash;搜索NeoPixel&mdash;安装<br style=" overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal" />
安装Adafruit_NeoPixel库,<br style=" overflow-wrap:break-word; color:#444444;Microsoft Yahei&quot;, Simsun; white-space:normal" />
下载<u style=" overflow-wrap:break-word">https://github.com/adafruit/Adafruit_NeoPixel</u></p>

<div>&nbsp;</div>

<p></p>

eagler8 发表于 2022-10-21 18:48

<p></p>

lugl4313820 发表于 2022-10-21 19:00

看到了一双苍霜的老手!

eagler8 发表于 2022-10-22 10:16

<p>&nbsp; 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)<br />
&nbsp; 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块<br />
&nbsp; 项目程序之一:LED循环绿色快闪测试</p>

<p>&nbsp;</p>

<pre>
<code>/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
项目程序之一:LED循环绿色快闪测试
*/

#include &lt;Adafruit_NeoPixel.h&gt;

#define PIN 6
#define MAX_LED 255

#define ADD true
#define SUB false

int val = 0;
boolean stat = ADD;

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

void setup() {
strip.begin();
strip.show();
}

void loop() {
uint8_t i, a = 0;
uint32_t color = strip.Color(255, 0, 0);
while (a &lt; 256)
{
    for (i = 0; i &lt; 255; i++)
    {
      if (i == a) strip.setPixelColor(i, color);
      else strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(2);
    a++;
}
}</code></pre>

<p>&nbsp;</p>

eagler8 发表于 2022-10-22 10:23

<p>实验场景图</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 10:34

<p>&nbsp; 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)</p>

<p>&nbsp; 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块</p>

<p>&nbsp; 项目程序之二:全屏LED呼吸灯</p>

<p>&nbsp;</p>

<pre>
<code>/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
项目程序之二:全屏LED呼吸灯
*/

#include &lt;FastLED.h&gt;

#define LED_PIN   6   
#define NUM_LEDS    256   
CRGB leds;

void setup() {
FastLED.addLeds&lt;WS2812, LED_PIN, GRB&gt;(leds, NUM_LEDS);
FastLED.setBrightness(20);
}

int h = 0;

void loop() {
for (int i = 0; i &lt; NUM_LEDS; i++) {
    leds = CHSV( h, 255, 255);
    FastLED.show();
}
delay(1);
h = (h + 3) % 255;
}</code></pre>

<p>&nbsp;</p>

eagler8 发表于 2022-10-22 10:36

<p>实验场景图</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 11:45

<p>&nbsp; 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)</p>

<p>&nbsp; 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块</p>

<p>&nbsp; 项目程序之三:简单的三色流水灯</p>

<p>&nbsp;</p>

<pre>
<code>/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
项目程序之三:简单的三色流水灯
*/

#include &lt;FastLED.h&gt;

#define LED_PIN    6
#define NUM_LEDS   256
CRGB leds;

void setup() {
FastLED.addLeds&lt;WS2812, LED_PIN, GRB&gt;(leds, NUM_LEDS);
FastLED.setBrightness(250);
}

void loop() {
for (int i = 0; i &lt; NUM_LEDS; i++) {
    leds = CRGB::Red;
    FastLED.show();
    delay(1);
    leds = CRGB::Black;
}
    for (int i = NUM_LEDS; i &gt; 0; i--) {
    leds = CRGB::Blue;
    FastLED.show();
    delay(1);
    leds = CRGB::Black;
}
    for (int i = 0; i &lt; NUM_LEDS; i++) {
    leds = CRGB::Green;
    FastLED.show();
    delay(1);
    leds = CRGB::Black;
}
      for (int i = NUM_LEDS; i &gt; 0; i--) {
    leds = CRGB::Blue;
    FastLED.show();
    delay(1);
    leds = CRGB::Black;
}
}</code></pre>

<p>&nbsp;</p>

eagler8 发表于 2022-10-22 11:56

<p>实验场景图&nbsp; 动态图</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 13:47

<p>&nbsp; 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)</p>

<p>&nbsp; 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块</p>

<p>&nbsp; 项目程序之四:循环快扫红绿蓝色LED满屏流水彩虹灯</p>

<p>&nbsp;</p>

<pre>
<code>/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
项目程序之四:循环快扫红绿蓝色LED满屏流水彩虹灯
*/

#include &lt;Adafruit_NeoPixel.h&gt;

#define PIN 6
#define BRIGHTNESS 256

Adafruit_NeoPixel strip = Adafruit_NeoPixel(256, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.setBrightness(30);
strip.begin();
strip.show();
}

void loop() {
colorWipe(strip.Color(150, 0, 0), 50); // Red
colorWipe(strip.Color(0, 150, 0), 50); // Green
colorWipe(strip.Color(0, 0, 150), 50); // Blue
colorWipe(strip.Color(150, 150, 150), 50); // BlueWite
rainbowCycle(1);

}

void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i &lt; strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(3);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j &lt; 256; j++) {
    for (i = 0; i &lt; strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) &amp; 255 ));
    }
    strip.show();
    delay(3);
}
}

void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j &lt; 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i &lt; strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) &amp; 255));
    }
    strip.show();
    delay(3);
}
}

uint32_t Wheel(byte WheelPos) {
if (WheelPos &lt; 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos &lt; 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}</code></pre>

<p>&nbsp;</p>

eagler8 发表于 2022-10-22 13:49

<p>实验场景图&nbsp; 动态图</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 13:51

<p>实验场景图&nbsp; 动态图2</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 15:04

<p>&nbsp; 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)</p>

<p>&nbsp; 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块</p>

<p>&nbsp; 项目程序之五:255位循环流水变幻呼吸灯</p>

<p>&nbsp;</p>

<pre>
<code>/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
项目程序之五:255位循环流水变幻呼吸灯
*/

// NeoPixel test program showing use of the WHITE channel for RGBW
// pixels only (won't look correct on regular RGB NeoPixel strips).

#include &lt;Adafruit_NeoPixel.h&gt;
#ifdef __AVR__
#include &lt;avr/power.h&gt; // Required for 16 MHz Adafruit Trinket
#endif

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

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT255

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

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB   Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB   Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

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

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

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

whiteOverRainbow(75, 5);

pulseWhite(5);

rainbowFade2White(3, 3, 1);
}

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

void whiteOverRainbow(int whiteSpeed, int whiteLength) {

if(whiteLength &gt;= strip.numPixels()) whiteLength = strip.numPixels() - 1;

int      head          = whiteLength - 1;
int      tail          = 0;
int      loops         = 3;
int      loopNum       = 0;
uint32_t lastTime      = millis();
uint32_t firstPixelHue = 0;

for(;;) { // Repeat forever (or until a 'break' or 'return')
    for(int i=0; i&lt;strip.numPixels(); i++) {// For each pixel in strip...
      if(((i &gt;= tail) &amp;&amp; (i &lt;= head)) ||      //If between head &amp; tail...
         ((tail &gt; head) &amp;&amp; ((i &gt;= tail) || (i &lt;= head)))) {
      strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
      } else {                                             // else set rainbow
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
      }
    }

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

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

    if((millis() - lastTime) &gt; whiteSpeed) { // Time to update head/tail?
      if(++head &gt;= strip.numPixels()) {      // Advance head, wrap around
      head = 0;
      if(++loopNum &gt;= loops) return;
      }
      if(++tail &gt;= strip.numPixels()) {      // Advance tail, wrap around
      tail = 0;
      }
      lastTime = millis();                   // Save time of last movement
    }
}
}

void pulseWhite(uint8_t wait) {
for(int j=0; j&lt;256; j++) { // Ramp up from 0 to 255
    // Fill entire strip with white at gamma-corrected brightness level 'j':
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(4);
}

for(int j=255; j&gt;=0; j--) { // Ramp down from 255 to 0
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(4);
}
}

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

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

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

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

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

    strip.show();
    delay(4);

    if(firstPixelHue &lt; 65536) {                              // First loop,
      if(fadeVal &lt; fadeMax) fadeVal++;                     // fade in
    } else if(firstPixelHue &gt;= ((rainbowLoops-1) * 65536)) { // Last loop,
      if(fadeVal &gt; 0) fadeVal--;                           // fade out
    } else {
      fadeVal = fadeMax; // Interim loop, make sure fade is at max
    }
}

for(int k=0; k&lt;whiteLoops; k++) {
    for(int j=0; j&lt;256; j++) { // Ramp up 0 to 255
      // Fill entire strip with white at gamma-corrected brightness level 'j':
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
    delay(20); // Pause 1 second
    for(int j=255; j&gt;=0; j--) { // Ramp down 255 to 0
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
}

delay(10); // Pause 1/2 second
}</code></pre>

<p>&nbsp;</p>

eagler8 发表于 2022-10-22 15:09

<p>实验场景图&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 15:11

<p>实验场景图 2</p>

<p>&nbsp;</p>

<p></p>

eagler8 发表于 2022-10-22 15:27

<p>&nbsp; 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)</p>

<p>&nbsp; 实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块</p>

<p>&nbsp; 项目程序之六:多彩流水灯变幻彩虹灯</p>

<p>&nbsp;</p>

<pre>
<code>/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
项目程序之六:多彩流水灯变幻彩虹灯
*/

#include &lt;Adafruit_NeoPixel.h&gt;    //needed for the WS2812
#include &lt;avr/pgmspace.h&gt;         //needed for PROGMEM

#define PIN 6                  //Pin 1 is DATA In on the bottom Ring
#define BRIGHTNESS 255             // brightness reduced



//Lookup for the Candle light
const unsigned int candles[] PROGMEM =
{
15, 10, 48, 45, 36, 19, 59, 29, 5, 43, 41, 39, 24, 3, 61
};

Adafruit_NeoPixel strip = Adafruit_NeoPixel(255, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
pinMode(PIN, OUTPUT);
strip.begin();
strip.setBrightness(BRIGHTNESS); // set brightness
strip.show(); // Initialize all pixels to 'off'
}

void loop() {
tree();
delay(100);

colorcrazy();

theaterChaseRainbow(50);

comet();

warpdrive();
warpdrive();

rainbowCycle(1);

rainbow(5);
rainbow(5);
rainbow(5);


colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue

//
//
//cometr();
//Tree light:

//
//warpdrive();
//
//
//comet();


/*
    // Some example procedures showing how to display to the pixels:
    colorWipe(strip.Color(255, 0, 0), 50); // Red
    colorWipe(strip.Color(0, 255, 0), 50); // Green
    colorWipe(strip.Color(0, 0, 255), 50); // Blue
    // Send a theater pixel chase in...
    theaterChase(strip.Color(127, 127, 127), 50); // White
    theaterChase(strip.Color(127,   0,   0), 50); // Red
    theaterChase(strip.Color(0,   0, 127), 50); // Blue
    rainbow(20);
    rainbowCycle(20);
    theaterChaseRainbow(50);
*/
}

//Sub-----------------------------------------------------------------------

//Comet
void comet() {
for (uint16_t i = strip.numPixels(); i &gt; 0; i--) {
    strip.setPixelColor(i, strip.Color(0, 0, 255));
    fadethemall(10);
    fadethemall(10);
}
}

void cometr() {
for (uint16_t i = strip.numPixels(); i &gt; 0; i--) {
    strip.setPixelColor(i, strip.Color(255, 0, 0));
    fadethemall(10);
    fadethemall(10);
}
}


//From top down white pulses
void warpdrive() {

//Top Led
strip.setPixelColor(60, strip.Color(255, 255, 255));
strip.show();
//fade a bit
for (int i = 0; i &lt; 20; i++)
{
    fadethemall(20);
}
//8 Ring
for (int i = 52; i &lt; 60; i++)
{
    strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
//fade a bit
for (int i = 0; i &lt; 20; i++)
{
    fadethemall(20);
}
//12 Ring
for (int i = 40; i &lt; 52; i++)
{
    strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
//fade a bit
for (int i = 0; i &lt; 20; i++)
{
    fadethemall(20);
}
//16 Ring
for (int i = 24; i &lt; 40; i++)
{
    strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
//fade a bit
for (int i = 0; i &lt; 20; i++)
{
    fadethemall(20);
}
//24 Ring
for (int i = 0; i &lt; 24; i++)
{
    strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
//fade a bit
for (int i = 0; i &lt; 20; i++)
{
    fadethemall(20);
}

//Extra by John Kerr
strip.setPixelColor(60, strip.Color(0, 0, 0));
strip.show();
//fade a bit
for (int i = 0; i &lt; 20; i++)
{
    fadethemall(20);
}

}

//This reduces the brightness of all leds
void fadethemall(uint8_t wait) {
for (uint16_t i = 0; i &lt; strip.numPixels(); i++) {
    uint32_t color = strip.getPixelColor(i);
    int r;
    int g;
    int b;
    r = (uint8_t)(color &gt;&gt; 16);
    g = (uint8_t)(color &gt;&gt;8);
    b = (uint8_t)color;

    if (r &gt; 0)
    {
      r = r - 1;
    }
    else
    {
      r = 0;
    }

    if (g &gt; 0)
    {
      g = g - 1;
    }
    else
    {
      g = 0;
    }

    if (b &gt; 0)
    {
      b = b - 1;
    }
    else
    {
      b = 0;
    }

    strip.setPixelColor(i, strip.Color(r, g, b));
}
strip.show();
delay(20);
}

//This drives the WS2812 in a crazy pattern, fun!
void colorcrazy() {
colorWipe(strip.Color(255, 0, 0), 25); // Red
colorWipe(strip.Color(0, 255, 0), 25); // Green
colorWipe(strip.Color(0, 0, 255), 25); // Blue
theaterChaseRainbow(5);
}

//This lights up the tree in green, then add the white "candles"
void tree() {

colorWipe(strip.Color(0, 50, 0), 50); // Green

//light "candles"
//Show the S:
for (int i = 0; i &lt; 16; i++)
{
    strip.setPixelColor(pgm_read_word(&amp;candles) - 1, strip.Color(255, 255, 255));
    strip.show();
    delay(20);
}
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i &lt; strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(20);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for (j = 0; j &lt; 256; j++) {
    for (i = 0; i &lt; strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) &amp; 255));
    }
    strip.show();
    delay(20);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for (j = 0; j &lt; 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i &lt; strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) &amp; 255));
    }
    strip.show();
    delay(20);
}
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j = 0; j &lt; 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q &lt; 3; q++) {
      for (int i = 0; i &lt; strip.numPixels(); i = i + 3) {
      strip.setPixelColor(i + q, c);//turn every third pixel on
      }
      strip.show();

      delay(20);

      for (int i = 0; i &lt; strip.numPixels(); i = i + 3) {
      strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j &lt; 256; j++) {   // cycle all 256 colors in the wheel
    for (int q = 0; q &lt; 3; q++) {
      for (int i = 0; i &lt; strip.numPixels(); i = i + 3) {
      strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
      }
      strip.show();

      delay(20);

      for (int i = 0; i &lt; strip.numPixels(); i = i + 3) {
      strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos &lt; 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos &lt; 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
    WheelPos -= 170;
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}</code></pre>

<p>&nbsp;</p>
页: [1] 2 3 4
查看完整版本: 【Arduino】168种传感器系列实验(214)---8x32位全彩WS2812B屏