找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 8198|回復(fù): 27
打印 上一主題 下一主題
收起左側(cè)

【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(147)---64位WS2812點(diǎn)陣屏

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
本帖最后由 eagler8 于 2020-2-29 16:06 編輯

37款傳感器與模塊的提法,在網(wǎng)絡(luò)上廣泛流傳,其實(shí)Arduino能夠兼容的傳感器模塊肯定是不止37種的。鑒于本人手頭積累了一些傳感器和執(zhí)行器模塊,依照實(shí)踐出真知(一定要?jiǎng)邮肿觯┑睦砟,以學(xué)習(xí)和交流為目的,這里準(zhǔn)備逐一動(dòng)手試試做實(shí)驗(yàn),不管成功與否,都會(huì)記錄下來(lái)---小小的進(jìn)步或是搞不定的問(wèn)題,希望能夠拋磚引玉。

【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
實(shí)驗(yàn)一百四十七:64位 WS2812B 8x8 RGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏





分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:513258 發(fā)表于 2020-2-29 16:05 | 只看該作者
WS2812B
是一個(gè)集控制電路與發(fā)光電路于一體的智能外控LED光源。其外型與一個(gè)5050LED燈珠相同,每個(gè)元件即為一個(gè)像素點(diǎn)。像素點(diǎn)內(nèi)部包含了智能數(shù)字接口數(shù)據(jù)鎖存信號(hào)整形放大驅(qū)動(dòng)電路,還包含有高精度的內(nèi)部振蕩器和12V高壓可編程定電流控制部分,有效保證了像素點(diǎn)光的顏色高度一致。

數(shù)據(jù)協(xié)議采用單線歸零碼的通訊方式,像素點(diǎn)在上電復(fù)位以后,DIN端接受從控制器傳輸過(guò)來(lái)的數(shù)據(jù),首先送過(guò)來(lái)的24bit數(shù)據(jù)被第一個(gè)像素點(diǎn)提取后,送到像素點(diǎn)內(nèi)部的數(shù)據(jù)鎖存器,剩余的數(shù)據(jù)經(jīng)過(guò)內(nèi)部整形處理電路整形放大后通過(guò)DO端口開(kāi)始轉(zhuǎn)發(fā)輸出給下一個(gè)級(jí)聯(lián)的像素點(diǎn),每經(jīng)過(guò)一個(gè)像素點(diǎn)的傳輸,信號(hào)減少24bit。像素點(diǎn)采用自動(dòng)整形轉(zhuǎn)發(fā)技術(shù),使得該像素點(diǎn)的級(jí)聯(lián)個(gè)數(shù)不受信號(hào)傳送的限制,僅僅受限信號(hào)傳輸速度要求。

LED具有低電壓驅(qū)動(dòng),環(huán)保節(jié)能,亮度高,散射角度大,一致性好,超低功率,超長(zhǎng)壽命等優(yōu)點(diǎn)。將控制電路集成于LED上面,電路變得更加簡(jiǎn)單,體積小,安裝更加簡(jiǎn)便。


回復(fù)

使用道具 舉報(bào)

板凳
ID:513258 發(fā)表于 2020-2-29 16:18 | 只看該作者

回復(fù)

使用道具 舉報(bào)

地板
ID:513258 發(fā)表于 2020-2-29 16:45 | 只看該作者

回復(fù)

使用道具 舉報(bào)

5#
ID:513258 發(fā)表于 2020-2-29 16:47 | 只看該作者

回復(fù)

使用道具 舉報(bào)

6#
ID:513258 發(fā)表于 2020-2-29 16:48 | 只看該作者

回復(fù)

使用道具 舉報(bào)

7#
ID:513258 發(fā)表于 2020-3-1 08:53 | 只看該作者


WS2812B主要特點(diǎn)
智能反接保護(hù),電源反接不會(huì)損壞IC。
IC控制電路與LED點(diǎn)光源公用一個(gè)電源。
控制電路與RGB芯片集成在一個(gè)5050封裝的元器件中,構(gòu)成一個(gè)完整的外控像素點(diǎn)。
內(nèi)置信號(hào)整形電路,任何一個(gè)像素點(diǎn)收到信號(hào)后經(jīng)過(guò)波形整形再輸出,保證線路波形畸變不會(huì)累加。
內(nèi)置上電復(fù)位和掉電復(fù)位電路。
每個(gè)像素點(diǎn)的三基色顏色可實(shí)現(xiàn)256級(jí)亮度顯示,完成16777216種顏色的全真色彩顯示,掃描頻率不低于400Hz/s。
串行級(jí)聯(lián)接口,能通過(guò)一根信號(hào)線完成數(shù)據(jù)的接收與解碼。
任意兩點(diǎn)傳傳輸距離在不超過(guò)5米時(shí)無(wú)需增加任何電路。
當(dāng)刷新速率30幀/秒時(shí),級(jí)聯(lián)數(shù)不小于1024點(diǎn)。
數(shù)據(jù)發(fā)送速度可達(dá)800Kbps。
光的顏色高度一致,性價(jià)比高。

主要應(yīng)用領(lǐng)域
LED全彩發(fā)光字燈串,LED全彩模組, LED全彩軟燈條硬燈條,LED護(hù)欄管。
LED點(diǎn)光源,LED像素屏,LED異形屏,各種電子產(chǎn)品,電器設(shè)備跑馬燈。

回復(fù)

使用道具 舉報(bào)

8#
ID:513258 發(fā)表于 2020-3-1 09:13 | 只看該作者


名稱:WS2812全彩矩陣LED模塊(64位燈珠)
尺寸:6.5*6.5cm
芯片:WS2812B(內(nèi)置于LED)
LED:5050封裝RGB全彩高亮
電壓:5V
端口:數(shù)字
平臺(tái):Arduino 單片機(jī)
控制方式:內(nèi)置控制芯片,只需一個(gè)IO口即可控制

回復(fù)

使用道具 舉報(bào)

9#
ID:513258 發(fā)表于 2020-3-1 09:26 | 只看該作者
模塊電原理圖



回復(fù)

使用道具 舉報(bào)

10#
ID:513258 發(fā)表于 2020-3-1 09:34 | 只看該作者
實(shí)驗(yàn)涉及到的幾個(gè)WS2812B相關(guān)庫(kù)
安裝FastLED庫(kù),工具—管理庫(kù)—搜索FastLED—安裝
安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
安裝Adafruit_NeoPixel庫(kù),
下載learn.adafruit點(diǎn)com/adafruit-neopixel-uberguide/arduino-library-installation



回復(fù)

使用道具 舉報(bào)

11#
ID:513258 發(fā)表于 2020-3-1 09:41 | 只看該作者

回復(fù)

使用道具 舉報(bào)

12#
ID:513258 發(fā)表于 2020-3-1 09:45 | 只看該作者
  程序之一:簡(jiǎn)單藍(lán)色流水燈
  實(shí)驗(yàn)接線
  Module    UNO
  VCC —— 3.3V(希望電流小一些)
  GND —— GND
  DI  ——  D6


  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),
  6.   下載https://learn.adafruit點(diǎn)com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之一:簡(jiǎn)單藍(lán)色流水燈
  8.   實(shí)驗(yàn)接線
  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上的哪個(gè)插腳與NeoPixels相連?
  19. #define PIN        6

  20. // Arduino上有多少個(gè)LED?
  21. #define NUMPIXELS 64

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

  23. #define DELAYVAL 30 //像素之間暫停的時(shí)間(毫秒)

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

  27. #endif
  28.   // 特定代碼結(jié)束

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

  31. void loop() {
  32.   pixels.clear(); //將所有像素顏色設(shè)置為“關(guān)閉”

  33.   //一串中的第一個(gè)新混合物是0,第二個(gè)是1,一直往上
  34.   //像素?cái)?shù)減1
  35.   for (int i = 0; i < NUMPIXELS; i++) { // 對(duì)于每個(gè)像素......

  36.     //Color()接受RGB值,從0,0,0到255,255,255
  37.     //這里我們使用的是中等明亮的藍(lán)色:
  38.     pixels.setPixelColor(i, pixels.Color(0, 0, 150));

  39.     pixels.show();   // 將更新的像素顏色發(fā)送到硬件

  40.     delay(DELAYVAL); // 在下一個(gè)通過(guò)循環(huán)之前暫停
  41.   }
  42. }
復(fù)制代碼



回復(fù)

使用道具 舉報(bào)

13#
ID:513258 發(fā)表于 2020-3-1 09:51 | 只看該作者

回復(fù)

使用道具 舉報(bào)

14#
ID:513258 發(fā)表于 2020-3-1 10:04 | 只看該作者
程序之二:粉色單燈流水燈

  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),

  6.   程序之二:粉色單燈流水燈
  7.   實(shí)驗(yàn)接線
  8.   Module    UNO
  9.   VCC —— 3.3V
  10.   GND —— GND
  11.   DI  ——  D6
  12. */

  13. #include <Adafruit_NeoPixel.h>

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

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

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

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

  21. void setup()
  22. {
  23.   strip.begin();           //初始化Adafruit_NeoPixel;
  24.   strip.show();           //顯示所有LED為關(guān)狀態(tài);
  25. }

  26. void loop()
  27. {
  28.   uint8_t i,a=0;                                       
  29.   uint32_t color = strip.Color(0, 150, 150);         //選擇所顯示的顏色
  30.   while(a<65)
  31.   {
  32.       for(i=0;i<64;i++)
  33.       {
  34.         if(i==a) strip.setPixelColor(i, color);     //第幾個(gè)LED點(diǎn)亮;
  35.         else strip.setPixelColor(i, 0);             //使其他LED全滅;
  36.       }
  37.        strip.show();                                //是LED顯示所選的顏色;
  38.        delay(50);                                   //延時(shí)50ms;
  39.        a++;                                         
  40.   }
  41. }
復(fù)制代碼



回復(fù)

使用道具 舉報(bào)

15#
ID:513258 發(fā)表于 2020-3-1 10:10 | 只看該作者
程序之三:四色交替流水燈


  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝FastLED庫(kù),工具—管理庫(kù)—搜索FastLED—安裝

  5.   程序之三:四色交替流水燈
  6.   實(shí)驗(yàn)接線
  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. }
復(fù)制代碼



回復(fù)

使用道具 舉報(bào)

16#
ID:513258 發(fā)表于 2020-3-1 10:13 | 只看該作者

回復(fù)

使用道具 舉報(bào)

17#
ID:513258 發(fā)表于 2020-3-1 10:36 | 只看該作者
程序之四:黑客帝國(guó)綠色流水燈

  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝FastLED庫(kù),工具—管理庫(kù)—搜索FastLED—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),

  6.   程序之四:黑客帝國(guó)綠色流水燈
  7.   實(shí)驗(yàn)接線
  8.   Module    UNO
  9.   VCC —— 3.3V
  10.   GND —— GND
  11.   DI  ——  D6
  12. */

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

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

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

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

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

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



回復(fù)

使用道具 舉報(bào)

18#
ID:513258 發(fā)表于 2020-3-1 10:45 | 只看該作者
程序之五:RGB傳輸測(cè)試滿屏變幻彩燈
  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),

  6.   程序之五:RGB傳輸測(cè)試滿屏變幻彩燈
  7.   實(shí)驗(yàn)接線
  8.   Module    UNO
  9.   VCC —— 3.3V
  10.   GND —— GND
  11.   DI  ——  D6
  12. */


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

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

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

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

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

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

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

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

  51.   whiteOverRainbow(75, 5);

  52.   pulseWhite(5);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  156.   delay(500); // Pause 1/2 second
  157. }
復(fù)制代碼






回復(fù)

使用道具 舉報(bào)

19#
ID:513258 發(fā)表于 2020-3-1 11:18 | 只看該作者
本帖最后由 eagler8 于 2020-3-1 11:46 編輯

程序之五:RGB傳輸測(cè)試滿屏變幻彩燈 視頻(52秒)

鏈接:https://v.youku.com/v_show/id_XNDU2ODQ2MDI0NA==.html



https://v.youku.com/v_show/id_XNDU2ODQ2MDI0NA==.html
回復(fù)

使用道具 舉報(bào)

20#
ID:513258 發(fā)表于 2020-3-1 11:31 | 只看該作者
【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  安裝Adafruit_NeoPixel庫(kù),
  下載:learn.adafruit點(diǎn)com/adafruit-neopixel-uberguide/arduino-library-installation

  程序之六:復(fù)合流水彩虹燈
  實(shí)驗(yàn)接線
  Module    UNO
  VCC —— 3.3V
  GND —— GND
  DI  ——  D6

  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),
  6.   下載https://learn.adafruit點(diǎn)com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之六:復(fù)合流水彩虹燈
  8.   實(shí)驗(yàn)接線
  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. }
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

21#
ID:513258 發(fā)表于 2020-3-1 11:57 | 只看該作者
程序之七:復(fù)合飄逸彩虹滿屏燈

  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),
  6.   下載https://learn.adafruit點(diǎn)com/adafruit-neopixel-uberguide/arduino-library-installation

  7.   程序之七:復(fù)合飄逸彩虹滿屏燈
  8.   實(shí)驗(yàn)接線
  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>
  17. #endif

  18. #define PIN 6

  19. // Parameter 1 = number of pixels in strip
  20. // Parameter 2 = Arduino pin number (most are valid)
  21. // Parameter 3 = pixel type flags, add together as needed:
  22. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  23. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  24. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  25. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  26. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  27. Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);

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

  32. void setup() {
  33.   // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  34.   #if defined (__AVR_ATtiny85__)
  35.     if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  36.   #endif
  37.   // End of trinket special code

  38.   strip.begin();
  39.   strip.setBrightness(50);
  40.   strip.show(); // Initialize all pixels to 'off'
  41. }

  42. void loop() {
  43.   // Some example procedures showing how to display to the pixels:
  44.   colorWipe(strip.Color(255, 0, 0), 50); // Red
  45.   colorWipe(strip.Color(0, 255, 0), 50); // Green
  46.   colorWipe(strip.Color(0, 0, 255), 50); // Blue
  47. //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  48.   // Send a theater pixel chase in...
  49.   theaterChase(strip.Color(127, 127, 127), 50); // White
  50.   theaterChase(strip.Color(127, 0, 0), 50); // Red
  51.   theaterChase(strip.Color(0, 0, 127), 50); // Blue

  52.   rainbow(20);
  53.   rainbowCycle(20);
  54.   theaterChaseRainbow(50);
  55. }

  56. // Fill the dots one after the other with a color
  57. void colorWipe(uint32_t c, uint8_t wait) {
  58.   for(uint16_t i=0; i<strip.numPixels(); i++) {
  59.     strip.setPixelColor(i, c);
  60.     strip.show();
  61.     delay(wait);
  62.   }
  63. }

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

  66.   for(j=0; j<256; j++) {
  67.     for(i=0; i<strip.numPixels(); i++) {
  68.       strip.setPixelColor(i, Wheel((i+j) & 255));
  69.     }
  70.     strip.show();
  71.     delay(wait);
  72.   }
  73. }

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

  77.   for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  78.     for(i=0; i< strip.numPixels(); i++) {
  79.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  80.     }
  81.     strip.show();
  82.     delay(wait);
  83.   }
  84. }

  85. //Theatre-style crawling lights.
  86. void theaterChase(uint32_t c, uint8_t wait) {
  87.   for (int j=0; j<10; j++) {  //do 10 cycles of chasing
  88.     for (int q=0; q < 3; q++) {
  89.       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  90.         strip.setPixelColor(i+q, c);    //turn every third pixel on
  91.       }
  92.       strip.show();

  93.       delay(wait);

  94.       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  95.         strip.setPixelColor(i+q, 0);        //turn every third pixel off
  96.       }
  97.     }
  98.   }
  99. }

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

  108.       delay(wait);

  109.       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  110.         strip.setPixelColor(i+q, 0);        //turn every third pixel off
  111.       }
  112.     }
  113.   }
  114. }

  115. // Input a value 0 to 255 to get a color value.
  116. // The colours are a transition r - g - b - back to r.
  117. uint32_t Wheel(byte WheelPos) {
  118.   WheelPos = 255 - WheelPos;
  119.   if(WheelPos < 85) {
  120.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  121.   }
  122.   if(WheelPos < 170) {
  123.     WheelPos -= 85;
  124.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  125.   }
  126.   WheelPos -= 170;
  127.   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  128. }
復(fù)制代碼



回復(fù)

使用道具 舉報(bào)

22#
ID:513258 發(fā)表于 2020-3-1 12:29 | 只看該作者
  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百四十六:64位 WS2812B8*8 xRGB 5050 LED模塊 ws2812s像素點(diǎn)陣屏
  4.   安裝NeoPixel庫(kù),工具—管理庫(kù)—搜索NeoPixel—安裝
  5.   安裝Adafruit_NeoPixel庫(kù),

  6.   程序之八:復(fù)合彩虹滾動(dòng)流水燈
  7.   實(shí)驗(yàn)接線
  8.   Module    UNO
  9.   VCC —— 3.3V
  10.   GND —— GND
  11.   DI  ——  D6
  12. */

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

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

  20. // How many NeoPixels are attached to the Arduino?
  21. #define LED_COUNT 64

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


  32. // setup() function -- runs once at startup --------------------------------

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

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


  44. // loop() function -- runs repeatedly as long as board is on ---------------

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

  50.   // Do a theater marquee effect in various colors...
  51.   theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
  52.   theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  53.   theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness

  54.   rainbow(10);             // Flowing rainbow cycle along the whole strip
  55.   theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
  56. }


  57. // Some functions of our own for creating animated effects -----------------

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

  70. // Theater-marquee-style chasing lights. Pass in a color (32-bit value,
  71. // a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
  72. // between frames.
  73. void theaterChase(uint32_t color, int wait) {
  74.   for(int a=0; a<10; a++) {  // Repeat 10 times...
  75.     for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
  76.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  77.       // 'c' counts up from 'b' to end of strip in steps of 3...
  78.       for(int c=b; c<strip.numPixels(); c += 3) {
  79.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  80.       }
  81.       strip.show(); // Update strip with new contents
  82.       delay(wait);  // Pause for a moment
  83.     }
  84.   }
  85. }

  86. // Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
  87. void rainbow(int wait) {
  88.   // Hue of first pixel runs 5 complete loops through the color wheel.
  89.   // Color wheel has a range of 65536 but it's OK if we roll over, so
  90.   // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  91.   // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  92.   for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
  93.     for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  94.       // Offset pixel hue by an amount to make one full revolution of the
  95.       // color wheel (range of 65536) along the length of the strip
  96.       // (strip.numPixels() steps):
  97.       int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  98.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  99.       // optionally add saturation and value (brightness) (each 0 to 255).
  100.       // Here we're using just the single-argument hue variant. The result
  101.       // is passed through strip.gamma32() to provide 'truer' colors
  102.       // before assigning to each pixel:
  103.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  104.     }
  105.     strip.show(); // Update strip with new contents
  106.     delay(wait);  // Pause for a moment
  107.   }
  108. }

  109. // Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
  110. void theaterChaseRainbow(int wait) {
  111.   int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  112.   for(int a=0; a<30; a++) {  // Repeat 30 times...
  113.     for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
  114.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  115.       // 'c' counts up from 'b' to end of strip in increments of 3...
  116.       for(int c=b; c<strip.numPixels(); c += 3) {
  117.         // hue of pixel 'c' is offset by an amount to make one full
  118.         // revolution of the color wheel (range 65536) along the length
  119.         // of the strip (strip.numPixels() steps):
  120.         int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
  121.         uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
  122.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  123.       }
  124.       strip.show();                // Update strip with new contents
  125.       delay(wait);                 // Pause for a moment
  126.       firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
  127.     }
  128.   }
  129. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

23#
ID:513258 發(fā)表于 2020-3-1 13:08 | 只看該作者
實(shí)驗(yàn)仿真編程(linkboy3.6)之一



回復(fù)

使用道具 舉報(bào)

24#
ID:513258 發(fā)表于 2020-3-1 13:21 | 只看該作者
本帖最后由 eagler8 于 2020-3-1 14:18 編輯

實(shí)驗(yàn)仿真編程(linkboy3.6)之二



回復(fù)

使用道具 舉報(bào)

25#
ID:513258 發(fā)表于 2020-3-1 14:18 | 只看該作者
實(shí)驗(yàn)仿真編程(linkboy3.6)之三




回復(fù)

使用道具 舉報(bào)

26#
ID:513258 發(fā)表于 2020-3-2 18:10 | 只看該作者
程序之四:黑客帝國(guó)綠色流水燈



回復(fù)

使用道具 舉報(bào)

27#
ID:513258 發(fā)表于 2020-3-4 16:38 | 只看該作者
回復(fù)

使用道具 舉報(bào)

28#
ID:205113 發(fā)表于 2025-4-5 12:31 | 只看該作者
內(nèi)容詳實(shí),找了很久,就這個(gè)帖子最詳細(xì)。感謝分享!
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表