久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8078|回復: 27
打印 上一主題 下一主題
收起左側

【Arduino】168種傳感器模塊系列實驗(147)---64位WS2812點陣屏

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

37款傳感器與模塊的提法,在網絡上廣泛流傳,其實Arduino能夠兼容的傳感器模塊肯定是不止37種的。鑒于本人手頭積累了一些傳感器和執行器模塊,依照實踐出真知(一定要動手做)的理念,以學習和交流為目的,這里準備逐一動手試試做實驗,不管成功與否,都會記錄下來---小小的進步或是搞不定的問題,希望能夠拋磚引玉。

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





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

使用道具 舉報

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

數據協議采用單線歸零碼的通訊方式,像素點在上電復位以后,DIN端接受從控制器傳輸過來的數據,首先送過來的24bit數據被第一個像素點提取后,送到像素點內部的數據鎖存器,剩余的數據經過內部整形處理電路整形放大后通過DO端口開始轉發輸出給下一個級聯的像素點,每經過一個像素點的傳輸,信號減少24bit。像素點采用自動整形轉發技術,使得該像素點的級聯個數不受信號傳送的限制,僅僅受限信號傳輸速度要求。

LED具有低電壓驅動,環保節能,亮度高,散射角度大,一致性好,超低功率,超長壽命等優點。將控制電路集成于LED上面,電路變得更加簡單,體積小,安裝更加簡便。


回復

使用道具 舉報

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

回復

使用道具 舉報

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

回復

使用道具 舉報

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

回復

使用道具 舉報

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

回復

使用道具 舉報

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


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

主要應用領域
LED全彩發光字燈串,LED全彩模組, LED全彩軟燈條硬燈條,LED護欄管。
LED點光源,LED像素屏,LED異形屏,各種電子產品,電器設備跑馬燈。

回復

使用道具 舉報

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


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

回復

使用道具 舉報

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



回復

使用道具 舉報

10#
ID:513258 發表于 2020-3-1 09:34 | 只看該作者
實驗涉及到的幾個WS2812B相關庫
安裝FastLED庫,工具—管理庫—搜索FastLED—安裝
安裝NeoPixel庫,工具—管理庫—搜索NeoPixel—安裝
安裝Adafruit_NeoPixel庫,
下載learn.adafruit點com/adafruit-neopixel-uberguide/arduino-library-installation



回復

使用道具 舉報

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

回復

使用道具 舉報

12#
ID:513258 發表于 2020-3-1 09:45 | 只看該作者
  程序之一:簡單藍色流水燈
  實驗接線
  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. }
復制代碼



回復

使用道具 舉報

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

回復

使用道具 舉報

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

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

  6.   程序之二:粉色單燈流水燈
  7.   實驗接線
  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為關狀態;
  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);     //第幾個LED點亮;
  35.         else strip.setPixelColor(i, 0);             //使其他LED全滅;
  36.       }
  37.        strip.show();                                //是LED顯示所選的顏色;
  38.        delay(50);                                   //延時50ms;
  39.        a++;                                         
  40.   }
  41. }
復制代碼



回復

使用道具 舉報

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


  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. }
復制代碼



回復

使用道具 舉報

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

回復

使用道具 舉報

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

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

  6.   程序之四:黑客帝國綠色流水燈
  7.   實驗接線
  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. }
復制代碼



回復

使用道具 舉報

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

  6.   程序之五:RGB傳輸測試滿屏變幻彩燈
  7.   實驗接線
  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. }
復制代碼






回復

使用道具 舉報

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

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

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



https://v.youku.com/v_show/id_XNDU2ODQ2MDI0NA==.html
回復

使用道具 舉報

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




回復

使用道具 舉報

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

  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>
  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. }
復制代碼



回復

使用道具 舉報

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

  6.   程序之八:復合彩虹滾動流水燈
  7.   實驗接線
  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. }
復制代碼


回復

使用道具 舉報

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



回復

使用道具 舉報

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

實驗仿真編程(linkboy3.6)之二



回復

使用道具 舉報

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




回復

使用道具 舉報

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



回復

使用道具 舉報

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

使用道具 舉報

28#
ID:205113 發表于 2025-4-5 12:31 | 只看該作者
內容詳實,找了很久,就這個帖子最詳細。感謝分享!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久久精品综合 | 中文字幕精品一区二区三区精品 | 免费一级淫片aaa片毛片a级 | 成人免费视频网站在线观看 | 在线观看av中文字幕 | 99精品一区二区 | 成人久草| 中文字幕一区二区三区四区五区 | 国产 欧美 日韩 一区 | 黄a在线观看 | 自拍偷拍亚洲一区 | 欧美午夜一区二区三区免费大片 | 欧美精品福利 | 亚洲视频在线一区 | 欧美一级久久 | 日韩精品福利 | 9999在线视频 | av黄色在线 | 国产第一页在线播放 | 久久久中文 | 日本久久福利 | 亚洲视频免费在线观看 | 免费在线观看一级毛片 | 国产69精品久久99不卡免费版 | 精品一区二区在线观看 | 国产亚洲一区二区三区 | 亚洲高清视频在线观看 | 国产精品揄拍一区二区久久国内亚洲精 | 亚洲成人在线免费 | 久久亚 | 色综合久久天天综合网 | 日本久久一区 | 亚洲永久免费 | 亚洲午夜精品 | 正在播放国产精品 | 久久久青草婷婷精品综合日韩 | 亚洲一区国产精品 | 成人在线观看免费 | 天天色影视综合 | av毛片| 97日韩精品 |