数码之家

 找回密码
 立即注册
搜索
查看: 2059|回复: 89

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

[复制链接]
发表于 2022-10-21 18:01:18 | 显示全部楼层 |阅读模式
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手试试多做实验,不管成功与否,都会记录下来——小小的进步或是搞不掂的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 可编程硬屏模块



本帖子中包含更多资源

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

x

打赏

参与人数 1家元 +20 收起 理由
玛德陛下 + 20 認真發帖

查看全部打赏

 楼主| 发表于 2022-10-21 18:11:03 | 显示全部楼层

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-21 18:15:40 | 显示全部楼层
WS2812B灯屏电原理参考图




本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

发表于 2022-10-21 18:17:04 | 显示全部楼层
系统教程吗。
有没有地方有微信小程序的源代码学习?
回复 支持 反对

使用道具 举报

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

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



本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-21 18:18:46 | 显示全部楼层
brianlee 发表于 2022-10-21 18:17
系统教程吗。
有没有地方有微信小程序的源代码学习?

谢谢,在做系列实验
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-21 18:20:09 | 显示全部楼层
brianlee 发表于 2022-10-21 18:17
系统教程吗。
有没有地方有微信小程序的源代码学习?

百度——微信小程序,你想找的,好像都有
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2022-10-21 18:31:20 | 显示全部楼层
实验涉及到的几个WS2812B相关库
安装FastLED库,工具—管理库—搜索FastLED—安装
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://github.com/adafruit/Adafruit_NeoPixel



本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-21 18:48:29 | 显示全部楼层

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 10:15:32 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  项目程序之一:LED循环绿色快闪测试

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

  6. #include <Adafruit_NeoPixel.h>

  7. #define PIN 6
  8. #define MAX_LED 255

  9. #define ADD true
  10. #define SUB false

  11. int val = 0;
  12. boolean stat = ADD;

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

  14. void setup() {
  15.   strip.begin();
  16.   strip.show();
  17. }

  18. void loop() {
  19.   uint8_t i, a = 0;
  20.   uint32_t color = strip.Color(255, 0, 0);
  21.   while (a < 256)
  22.   {
  23.     for (i = 0; i < 255; i++)
  24.     {
  25.       if (i == a) strip.setPixelColor(i, color);
  26.       else strip.setPixelColor(i, 0);
  27.     }
  28.     strip.show();
  29.     delay(2);
  30.     a++;
  31.   }
  32. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 10:15:53 | 显示全部楼层

有空多交流
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 10:22:52 | 显示全部楼层
实验场景图



本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 10:34:28 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  项目程序之二:全屏LED呼吸灯

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

  6. #include <FastLED.h>

  7. #define LED_PIN     6     
  8. #define NUM_LEDS    256   
  9. CRGB leds[NUM_LEDS];

  10. void setup() {
  11.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  12.   FastLED.setBrightness(20);  
  13. }

  14. int h = 0;

  15. void loop() {
  16.   for (int i = 0; i < NUM_LEDS; i++) {
  17.     leds[i] = CHSV( h, 255, 255);
  18.     FastLED.show();
  19.   }
  20.   delay(1);
  21.   h = (h + 3) % 255;
  22. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 10:36:22 | 显示全部楼层
实验场景图


本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 11:45:26 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  项目程序之三:简单的三色流水灯

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

  6. #include <FastLED.h>

  7. #define LED_PIN    6
  8. #define NUM_LEDS   256
  9. CRGB leds[NUM_LEDS];

  10. void setup() {
  11.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  12.   FastLED.setBrightness(250);  
  13. }

  14. void loop() {
  15.   for (int i = 0; i < NUM_LEDS; i++) {
  16.     leds[i] = CRGB::Red;
  17.     FastLED.show();
  18.     delay(1);
  19.     leds[i] = CRGB::Black;
  20.   }
  21.     for (int i = NUM_LEDS; i > 0; i--) {
  22.     leds[i] = CRGB::Blue;
  23.     FastLED.show();
  24.     delay(1);
  25.     leds[i] = CRGB::Black;
  26.   }
  27.     for (int i = 0; i < NUM_LEDS; i++) {
  28.     leds[i] = CRGB::Green;
  29.     FastLED.show();
  30.     delay(1);
  31.     leds[i] = CRGB::Black;
  32.   }
  33.       for (int i = NUM_LEDS; i > 0; i--) {
  34.     leds[i] = CRGB::Blue;
  35.     FastLED.show();
  36.     delay(1);
  37.     leds[i] = CRGB::Black;
  38.   }
  39. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 11:56:45 | 显示全部楼层
实验场景图  动态图



本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 13:47:33 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  项目程序之四:循环快扫红绿蓝色LED满屏流水彩虹灯

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

  6. #include <Adafruit_NeoPixel.h>

  7. #define PIN 6
  8. #define BRIGHTNESS 256

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

  10. void setup() {
  11.   strip.setBrightness(30);
  12.   strip.begin();
  13.   strip.show();
  14. }

  15. void loop() {
  16.   colorWipe(strip.Color(150, 0, 0), 50); // Red
  17.   colorWipe(strip.Color(0, 150, 0), 50); // Green
  18.   colorWipe(strip.Color(0, 0, 150), 50); // Blue
  19.   colorWipe(strip.Color(150, 150, 150), 50); // BlueWite
  20.   rainbowCycle(1);

  21. }

  22. void colorWipe(uint32_t c, uint8_t wait) {
  23.   for (uint16_t i = 0; i < strip.numPixels(); i++) {
  24.     strip.setPixelColor(i, c);
  25.     strip.show();
  26.     delay(3);
  27.   }
  28. }

  29. void rainbow(uint8_t wait) {
  30.   uint16_t i, j;
  31.   for (j = 0; j < 256; j++) {
  32.     for (i = 0; i < strip.numPixels(); i++) {
  33.       strip.setPixelColor(i, Wheel((i + j) & 255 ));
  34.     }
  35.     strip.show();
  36.     delay(3);
  37.   }
  38. }

  39. void rainbowCycle(uint8_t wait) {
  40.   uint16_t i, j;
  41.   for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
  42.     for (i = 0; i < strip.numPixels(); i++) {
  43.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  44.     }
  45.     strip.show();
  46.     delay(3);
  47.   }
  48. }

  49. uint32_t Wheel(byte WheelPos) {
  50.   if (WheelPos < 85) {
  51.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  52.   } else if (WheelPos < 170) {
  53.     WheelPos -= 85;
  54.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  55.   } else {
  56.     WheelPos -= 170;
  57.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  58.   }
  59. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 13:49:34 | 显示全部楼层
实验场景图  动态图



本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 13:51:44 | 显示全部楼层
实验场景图  动态图2



本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-22 15:04:28 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 硬屏模块
  项目程序之五:255位循环流水变幻呼吸灯
/*
  【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 <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // 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_COUNT  255

// 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_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 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__) && (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<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 >= 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<strip.numPixels(); i++) {  // For each pixel in strip...
      if(((i >= tail) && (i <= head)) ||      //  If between head & tail...
         ((tail > head) && ((i >= tail) || (i <= 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) > whiteSpeed) { // Time to update head/tail?
      if(++head >= strip.numPixels()) {      // Advance head, wrap around
        head = 0;
        if(++loopNum >= loops) return;
      }
      if(++tail >= 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<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>=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 < rainbowLoops*65536;
    firstPixelHue += 256) {

    for(int i=0; i<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 < 65536) {                              // First loop,
      if(fadeVal < fadeMax) fadeVal++;                       // fade in
    } else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
      if(fadeVal > 0) fadeVal--;                             // fade out
    } else {
      fadeVal = fadeMax; // Interim loop, make sure fade is at max
    }
  }

  for(int k=0; k<whiteLoops; k++) {
    for(int j=0; j<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>=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
}

回复 支持 反对

使用道具 举报

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

本版积分规则

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

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2025-5-3 01:51 , Processed in 0.202801 second(s), 10 queries , Redis On.

Powered by Discuz!

© 2006-2025 MyDigit.Net

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