欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

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

QQ登錄

只需一步,快速開始

搜索
查看: 9949|回復(fù): 32
收起左側(cè)

【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(131)--24位WS2812環(huán)形燈板

[復(fù)制鏈接]
ID:513258 發(fā)表于 2019-10-1 06:50 | 顯示全部樓層 |閱讀模式
37款傳感器與模塊的提法,在網(wǎng)絡(luò)上廣泛流傳,其實(shí)Arduino能夠兼容的傳感器模塊肯定是不止37種的。鑒于本人手頭積累了一些傳感器和模塊,依照實(shí)踐出真知(一定要?jiǎng)邮肿觯┑睦砟,以學(xué)習(xí)和交流為目的,這里準(zhǔn)備逐一動(dòng)手試試做實(shí)驗(yàn),不管成功與否,都會(huì)記錄下來---小小的進(jìn)步或是搞不定的問題,希望能夠拋磚引玉。

【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板


0.jpg

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 06:52 | 顯示全部樓層
WS2812
是在尋求一種簡單,可擴(kuò)展和經(jīng)濟(jì)實(shí)惠的全彩LED的最新進(jìn)展。紅色,綠色和藍(lán)色LED與驅(qū)動(dòng)器芯片一起集成到通過單線控制的微小表面貼裝封裝中。它們可以單獨(dú)使用,鏈接成更長的字符串或組裝成更有趣的形狀因數(shù);赪S2812的 LED 驅(qū)動(dòng)器,使用單線控制協(xié)議,可分別尋址RGB彩色像素和色帶。專用LED驅(qū)動(dòng)器芯片的到來帶來了可喜的緩解,減輕了微控制器的繁瑣工作,使人們可以專注于應(yīng)用與創(chuàng)造。

01.jpg


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 07:33 | 顯示全部樓層
07 (1).gif

該Adafruit NeoPixel環(huán)包含24個(gè)可單獨(dú)尋址的RGB LED,這些LED以緊密間隔排列,所有這些均可通過微控制器的單個(gè)數(shù)字輸出進(jìn)行控制。該環(huán)的外徑為2.6英寸(66毫米),可以將多個(gè)環(huán)鏈接在一起,使其非常適合為小型機(jī)器人或可穿戴電子項(xiàng)目增加光澤。

功能和規(guī)格
24個(gè)可單獨(dú)尋址的RGB LED(基于SK6812-或WS2812B的NeoPixels)
圓形外徑2.6英寸(66毫米),內(nèi)徑2.05英寸(52.5毫米)
24位色彩控制(每通道8位PWM);每像素1680萬種顏色
單線數(shù)字控制接口
工作電壓:5 V
每個(gè)RGB LED在5 V時(shí)消耗大約50 mA的電流,紅色,綠色和藍(lán)色在全亮度下(環(huán)最大為1.2 A)
多個(gè)NeoPixel環(huán)可鏈接在一起

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 07:40 | 顯示全部樓層
07 (1).jpg

07 (2).jpg


24位WS2812 5050 RGB LED智能全彩RGB燈環(huán)開發(fā)板, 產(chǎn)品(直徑):86mm ,重量:6g ,電壓:DC4-7V范圍供電,通信接口:單線通訊

LED驅(qū)動(dòng)芯片WS2812(集成在LED里面)
智能反接保護(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)過波形整形再輸出,保證線路波形畸變不會(huì)累加。
內(nèi)置上電重定和掉電重定電路。
每個(gè)圖元點(diǎn)的三基色顏色可實(shí)現(xiàn)256級(jí)亮度顯示,完成16777216種顏色的全真色彩顯示,掃描頻率不低于400Hz/s。
串列級(jí)聯(lián)介面,能通過一根信號(hào)線完成資料的接收與解碼。
任意兩點(diǎn)傳傳輸距離在不超過5米時(shí)無需增加任何電路。
當(dāng)刷新速率30幀/秒時(shí),級(jí)聯(lián)數(shù)不小于1024點(diǎn)。
資料發(fā)送速度可達(dá)800Kbps。
光的顏色高度一致,性價(jià)比高。

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 07:43 | 顯示全部樓層
06.jpg
5050高亮LED,內(nèi)置控制芯片,僅需1個(gè)IO口即可控制多個(gè)LED
芯片內(nèi)置整形電路,信號(hào)畸變不會(huì)累計(jì),穩(wěn)定顯示
三基色256級(jí)亮度調(diào)劑,16萬色真彩顯示效果,掃描頻率不低于400Hz/S
串行連級(jí)接口,能通過一根信號(hào)線完成數(shù)據(jù)的接收與解碼
高亮LED,光色亮度一致性高
兩端有連級(jí)接口(DIN DOUT),可以串接

WS2813B是一個(gè)集控制電路與發(fā)光電路于一體的智慧外控LED光源。其外型與一個(gè)5050LED燈珠相同,每個(gè)元件即為一個(gè)圖元點(diǎn)。圖元點(diǎn)內(nèi)部包含了智慧數(shù)位介面資料鎖存信號(hào)整形放大驅(qū)動(dòng)電路,還包含有高精度的內(nèi)部振蕩器和12V高壓可編程定電流控制部分,有效保證了圖元點(diǎn)光的顏色高度一致。
資料協(xié)定采用單線歸零碼的通訊方式,圖元點(diǎn)在上電重定以后,DIN端接受從控制器傳輸過來的資料,首先送過來的24bit資料被第一個(gè)圖元點(diǎn)提取后,送到圖元點(diǎn)內(nèi)部的資料鎖存器,剩余的資料經(jīng)過內(nèi)部整形處理電路整形放大后通過DO埠開始轉(zhuǎn)發(fā)輸出給下一個(gè)級(jí)聯(lián)的圖元點(diǎn),每經(jīng)過一個(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é)能,亮度高,散射角度大,一致性好,超低功率,超長壽命等優(yōu)點(diǎn)。將控制電路集成于LED上面,電路變得更加簡單,體積小,安裝更加簡便。

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 08:51 | 顯示全部樓層
05 (1).jpg
連接
LED環(huán)具有四個(gè)連接點(diǎn)。

標(biāo)為GND的引腳為接地引腳,應(yīng)連接至控制LED的微控制器的接地引腳,也應(yīng)連接至電源的負(fù)極。

標(biāo)有PWR + 5V的引腳是電源輸入引腳,應(yīng)連接到合適的電源。5 V的輸入電壓用于為環(huán)供電,當(dāng)以全亮度輸出白色時(shí),環(huán)上的每個(gè)LED在5 V時(shí)可消耗高達(dá)50 mA的電流。這意味著該環(huán)最多可吸收約1.2 A電流。

標(biāo)為“ 數(shù)據(jù)輸入 ”的引腳是一個(gè)輸入,用于接收控制LED的信號(hào)。該引腳應(yīng)連接至基于SK6812 / WS281x的LED產(chǎn)品的微控制器輸出引腳或信號(hào)輸出引腳。

標(biāo)有“ 數(shù)據(jù)輸出 ”的引腳是可選的。它可以連接到另一個(gè)基于SK6812 / WS281x的LED產(chǎn)品的數(shù)據(jù)輸入引腳,以形成一條鏈。

我們的0.1英寸排針可以用來連接環(huán)的四個(gè)針,也可以將導(dǎo)線直接焊接到板上。環(huán)并不與任何標(biāo)頭銷或連接器發(fā)貨。

如果在使用NeoPixels時(shí)未采取適當(dāng)?shù)念A(yù)防措施,則很容易損壞它們。通常,對(duì)于基于SK6812 / WS2812B的產(chǎn)品,建議在接地線和電源線之間添加至少10 F的電容器,并在微控制器和信號(hào)輸入引腳之間添加100Ω至1000Ω的電阻。

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 09:00 | 顯示全部樓層
模塊電原理圖
09.jpg

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 09:03 | 顯示全部樓層
ATTiny85與WS2812 LED環(huán)配合使用示意圖
10 (1).jpg

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 10:06 | 顯示全部樓層
/*
  【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  項(xiàng)目一:循環(huán)點(diǎn)亮24位綠色LED
  Module      UNO
  VCC   ——   5V
  GND  ——   GND
  DI    ——   D6
*/

#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?
#define PIN        6 // On Trinket or Gemma, suggest changing this to 1

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24 // Popular NeoPixel ring size

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 300 // Time (in milliseconds) to pause between pixels

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.

  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop() {
  pixels.clear(); // Set all pixel colors to 'off'

  // The first NeoPixel in a strand is #0, second is 1, all the way up
  // to the count of pixels minus one.
  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...

    // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
    // Here we're using a moderately bright green color:
    pixels.setPixelColor(i, pixels.Color(0, 150, 0));

    pixels.show();   // Send the updated pixel colors to the hardware.

    delay(DELAYVAL); // Pause before next pass through loop
  }
}

回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 10:17 | 顯示全部樓層
11.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 10:33 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目二:循環(huán)快掃24位紅綠藍(lán)色LED流水燈
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

  10. #include <FastLED.h>
  11. #define LED_PIN     6
  12. #define NUM_LEDS    24
  13. CRGB leds[NUM_LEDS];
  14. void setup() {
  15.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  16. }
  17. void loop() {
  18.   for (int i = 0; i <= 23; i++) {
  19.     leds[i] = CRGB ( 0, 0, 255);
  20.     FastLED.show();
  21.     delay(40);
  22.   }
  23.   for (int i = 0; i <= 23; i++) {
  24.     leds[i] = CRGB ( 255, 0, 0);
  25.     FastLED.show();
  26.     delay(40);
  27.   }
  28.   for (int i = 0; i <= 23; i++) {
  29.     leds[i] = CRGB ( 0, 255, 0);
  30.     FastLED.show();
  31.     delay(40);
  32.   }
  33. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 10:45 | 顯示全部樓層
17-.gif
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 12:00 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目三:使用紅色、綠色和藍(lán)色三種參數(shù)將任何LED設(shè)置為任何顏色
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

  10. #include <FastLED.h>
  11. #define LED_PIN     6
  12. #define NUM_LEDS    24
  13. CRGB leds[NUM_LEDS];
  14. void setup() {
  15.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  16.   
  17. }
  18. void loop() {
  19.   
  20.   leds[0] = CRGB(255, 0, 0);
  21.   FastLED.show();
  22.   delay(500);  
  23.   leds[1] = CRGB(0, 255, 0);
  24.   FastLED.show();
  25.   delay(500);
  26.   leds[2] = CRGB(0, 0, 255);
  27.   FastLED.show();
  28.   delay(500);
  29.   leds[5] = CRGB(150, 0, 255);
  30.   FastLED.show();
  31.   delay(500);
  32.   leds[9] = CRGB(255, 200, 20);
  33.   FastLED.show();
  34.   delay(500);
  35.   leds[14] = CRGB(85, 60, 180);
  36.   FastLED.show();
  37.   delay(500);
  38.   leds[19] = CRGB(50, 255, 20);
  39.   FastLED.show();
  40.   delay(500);
  41. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 12:07 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目四:流水燈變幻彩虹燈
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

  10. #include <Adafruit_NeoPixel.h>

  11. #define PIN 6
  12. #define BRIGHTNESS 24

  13. Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

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

  19. void loop() {
  20.   colorWipe(strip.Color(150, 0, 0), 50); // Red
  21.   colorWipe(strip.Color(0, 150, 0), 50); // Green
  22.   colorWipe(strip.Color(0, 0, 150), 50); // Blue
  23.   colorWipe(strip.Color(150, 150, 150), 50); // BlueWite
  24.   rainbowCycle(1);

  25. }

  26. void colorWipe(uint32_t c, uint8_t wait) {
  27.   for (uint16_t i = 0; i < strip.numPixels(); i++) {
  28.     strip.setPixelColor(i, c);
  29.     strip.show();
  30.     delay(wait);
  31.   }
  32. }

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

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

  53. uint32_t Wheel(byte WheelPos) {
  54.   if (WheelPos < 85) {
  55.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  56.   } else if (WheelPos < 170) {
  57.     WheelPos -= 85;
  58.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  59.   } else {
  60.     WheelPos -= 170;
  61.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  62.   }
  63. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 12:21 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目五:循環(huán)流水變幻呼吸燈
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

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

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

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

  19. // How many NeoPixels are attached to the Arduino?
  20. #define LED_COUNT  24

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

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

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

  50.   whiteOverRainbow(75, 5);

  51.   pulseWhite(5);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 12:56 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目六:多彩流水燈變幻彩虹燈
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

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

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

  17. // How many NeoPixels are attached to the Arduino?
  18. #define LED_COUNT 24

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


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

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

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


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

  42. void loop() {
  43.   // Fill along the length of the strip in various colors...
  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.   // Do a theater marquee effect in various colors...
  48.   theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
  49.   theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  50.   theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness

  51.   rainbow(10);             // Flowing rainbow cycle along the whole strip
  52.   theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
  53. }


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

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

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

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


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 13:03 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目七:多彩流水燈變幻彩虹燈之三
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

  10. #include <Adafruit_NeoPixel.h>    //needed for the WS2812
  11. #include <avr/pgmspace.h>         //needed for PROGMEM

  12. #define PIN 6                    //Pin 1 is DATA In on the bottom Ring
  13. #define BRIGHTNESS 24             // brightness reduced



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

  19. Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

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

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

  30. void loop() {
  31.   tree();
  32.   delay(1000);

  33.   colorcrazy();

  34.   theaterChaseRainbow(50);

  35.   comet();

  36.   warpdrive();
  37.   warpdrive();

  38.   rainbowCycle(1);

  39.   rainbow(5);
  40.   rainbow(5);
  41.   rainbow(5);


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

  45.   //
  46.   //
  47.   //  cometr();
  48.   //Tree light:

  49.   //
  50.   //  warpdrive();
  51.   //
  52.   //
  53.   //  comet();


  54.   /*
  55.     // Some example procedures showing how to display to the pixels:
  56.     colorWipe(strip.Color(255, 0, 0), 50); // Red
  57.     colorWipe(strip.Color(0, 255, 0), 50); // Green
  58.     colorWipe(strip.Color(0, 0, 255), 50); // Blue
  59.     // Send a theater pixel chase in...
  60.     theaterChase(strip.Color(127, 127, 127), 50); // White
  61.     theaterChase(strip.Color(127,   0,   0), 50); // Red
  62.     theaterChase(strip.Color(  0,   0, 127), 50); // Blue
  63.     rainbow(20);
  64.     rainbowCycle(20);
  65.     theaterChaseRainbow(50);
  66.   */
  67. }

  68. //Sub-----------------------------------------------------------------------

  69. //Comet
  70. void comet() {
  71.   for (uint16_t i = strip.numPixels(); i > 0; i--) {
  72.     strip.setPixelColor(i, strip.Color(0, 0, 255));
  73.     fadethemall(10);
  74.     fadethemall(10);
  75.   }
  76. }

  77. void cometr() {
  78.   for (uint16_t i = strip.numPixels(); i > 0; i--) {
  79.     strip.setPixelColor(i, strip.Color(255, 0, 0));
  80.     fadethemall(10);
  81.     fadethemall(10);
  82.   }
  83. }


  84. //From top down white pulses
  85. void warpdrive() {

  86.   //Top Led
  87.   strip.setPixelColor(60, strip.Color(255, 255, 255));
  88.   strip.show();
  89.   //fade a bit
  90.   for (int i = 0; i < 20; i++)
  91.   {
  92.     fadethemall(20);
  93.   }
  94.   //8 Ring
  95.   for (int i = 52; i < 60; i++)
  96.   {
  97.     strip.setPixelColor(i, strip.Color(255, 255, 255));
  98.   }
  99.   strip.show();
  100.   //fade a bit
  101.   for (int i = 0; i < 20; i++)
  102.   {
  103.     fadethemall(20);
  104.   }
  105.   //12 Ring
  106.   for (int i = 40; i < 52; i++)
  107.   {
  108.     strip.setPixelColor(i, strip.Color(255, 255, 255));
  109.   }
  110.   strip.show();
  111.   //fade a bit
  112.   for (int i = 0; i < 20; i++)
  113.   {
  114.     fadethemall(20);
  115.   }
  116.   //16 Ring
  117.   for (int i = 24; i < 40; i++)
  118.   {
  119.     strip.setPixelColor(i, strip.Color(255, 255, 255));
  120.   }
  121.   strip.show();
  122.   //fade a bit
  123.   for (int i = 0; i < 20; i++)
  124.   {
  125.     fadethemall(20);
  126.   }
  127.   //24 Ring
  128.   for (int i = 0; i < 24; i++)
  129.   {
  130.     strip.setPixelColor(i, strip.Color(255, 255, 255));
  131.   }
  132.   strip.show();
  133.   //fade a bit
  134.   for (int i = 0; i < 20; i++)
  135.   {
  136.     fadethemall(20);
  137.   }

  138.   //Extra by John Kerr
  139.   strip.setPixelColor(60, strip.Color(0, 0, 0));
  140.   strip.show();
  141.   //fade a bit
  142.   for (int i = 0; i < 20; i++)
  143.   {
  144.     fadethemall(20);
  145.   }

  146. }

  147. //This reduces the brightness of all leds
  148. void fadethemall(uint8_t wait) {
  149.   for (uint16_t i = 0; i < strip.numPixels(); i++) {
  150.     uint32_t color = strip.getPixelColor(i);
  151.     int r;
  152.     int g;
  153.     int b;
  154.     r = (uint8_t)(color >> 16);
  155.     g = (uint8_t)(color >>  8);
  156.     b = (uint8_t)color;

  157.     if (r > 0)
  158.     {
  159.       r = r - 1;
  160.     }
  161.     else
  162.     {
  163.       r = 0;
  164.     }

  165.     if (g > 0)
  166.     {
  167.       g = g - 1;
  168.     }
  169.     else
  170.     {
  171.       g = 0;
  172.     }

  173.     if (b > 0)
  174.     {
  175.       b = b - 1;
  176.     }
  177.     else
  178.     {
  179.       b = 0;
  180.     }

  181.     strip.setPixelColor(i, strip.Color(r, g, b));
  182.   }
  183.   strip.show();
  184.   delay(wait);
  185. }

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

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

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

  196.   //light "candles"
  197.   //Show the S:
  198.   for (int i = 0; i < 16; i++)
  199.   {
  200.     strip.setPixelColor(pgm_read_word(&candles[i]) - 1, strip.Color(255, 255, 255));
  201.     strip.show();
  202.     delay(50);
  203.   }
  204. }

  205. // Fill the dots one after the other with a color
  206. void colorWipe(uint32_t c, uint8_t wait) {
  207.   for (uint16_t i = 0; i < strip.numPixels(); i++) {
  208.     strip.setPixelColor(i, c);
  209.     strip.show();
  210.     delay(wait);
  211.   }
  212. }

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

  215.   for (j = 0; j < 256; j++) {
  216.     for (i = 0; i < strip.numPixels(); i++) {
  217.       strip.setPixelColor(i, Wheel((i + j) & 255));
  218.     }
  219.     strip.show();
  220.     delay(wait);
  221.   }
  222. }

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

  226.   for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
  227.     for (i = 0; i < strip.numPixels(); i++) {
  228.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  229.     }
  230.     strip.show();
  231.     delay(wait);
  232.   }
  233. }

  234. //Theatre-style crawling lights.
  235. void theaterChase(uint32_t c, uint8_t wait) {
  236.   for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
  237.     for (int q = 0; q < 3; q++) {
  238.       for (int i = 0; i < strip.numPixels(); i = i + 3) {
  239.         strip.setPixelColor(i + q, c);  //turn every third pixel on
  240.       }
  241.       strip.show();

  242.       delay(wait);

  243.       for (int i = 0; i < strip.numPixels(); i = i + 3) {
  244.         strip.setPixelColor(i + q, 0);      //turn every third pixel off
  245.       }
  246.     }
  247.   }
  248. }

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

  257.       delay(wait);

  258.       for (int i = 0; i < strip.numPixels(); i = i + 3) {
  259.         strip.setPixelColor(i + q, 0);      //turn every third pixel off
  260.       }
  261.     }
  262.   }
  263. }

  264. // Input a value 0 to 255 to get a color value.
  265. // The colours are a transition r - g - b - back to r.
  266. uint32_t Wheel(byte WheelPos) {
  267.   WheelPos = 255 - WheelPos;
  268.   if (WheelPos < 85) {
  269.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  270.   } else if (WheelPos < 170) {
  271.     WheelPos -= 85;
  272.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  273.   } else {
  274.     WheelPos -= 170;
  275.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  276.   }
  277. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 13:22 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目八:綠色到粉紅色,也沿著環(huán)形移動(dòng)
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

  10. #include <PololuLedStrip.h>

  11. // Create an ledStrip object and specify the pin it will use.
  12. PololuLedStrip<6> ledStrip;

  13. // Create a buffer for holding the colors (3 bytes per color).
  14. #define LED_COUNT 60
  15. rgb_color colors[LED_COUNT];

  16. void setup()
  17. {
  18. }

  19. void loop()
  20. {
  21.   // Update the colors.
  22.   byte time = millis() >> 2;
  23.   for (uint16_t i = 0; i < LED_COUNT; i++)
  24.   {
  25.     byte x = time - 8*i;
  26.     colors[i] = rgb_color(x, 255 - x, x);
  27.   }

  28.   // Write the colors to the LED strip.
  29.   ledStrip.write(colors, LED_COUNT);

  30.   delay(10);
  31. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 13:26 | 顯示全部樓層
  1. /*
  2.   【Arduino】108種傳感器模塊系列實(shí)驗(yàn)(資料+代碼+圖形+仿真)
  3.   實(shí)驗(yàn)一百三十一:24位 WS2812 5050 RGB LED 內(nèi)置全彩驅(qū)動(dòng)彩燈 圓形開發(fā)板
  4.   項(xiàng)目九:一道移動(dòng)的彩虹
  5.   Module      UNO
  6.   VCC   ——   5V
  7.   GND  ——   GND
  8.   DI    ——   D6
  9. */

  10. #include <PololuLedStrip.h>

  11. // Create an ledStrip object and specify the pin it will use.
  12. PololuLedStrip<6> ledStrip;

  13. // Create a buffer for holding the colors (3 bytes per color).
  14. #define LED_COUNT 60
  15. rgb_color colors[LED_COUNT];

  16. void setup()
  17. {
  18. }

  19. // Converts a color from HSV to RGB.
  20. // h is hue, as a number between 0 and 360.
  21. // s is the saturation, as a number between 0 and 255.
  22. // v is the value, as a number between 0 and 255.
  23. rgb_color hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
  24. {
  25.     uint8_t f = (h % 60) * 255 / 60;
  26.     uint8_t p = (255 - s) * (uint16_t)v / 255;
  27.     uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
  28.     uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
  29.     uint8_t r = 0, g = 0, b = 0;
  30.     switch((h / 60) % 6){
  31.         case 0: r = v; g = t; b = p; break;
  32.         case 1: r = q; g = v; b = p; break;
  33.         case 2: r = p; g = v; b = t; break;
  34.         case 3: r = p; g = q; b = v; break;
  35.         case 4: r = t; g = p; b = v; break;
  36.         case 5: r = v; g = p; b = q; break;
  37.     }
  38.     return rgb_color(r, g, b);
  39. }

  40. void loop()
  41. {
  42.   // Update the colors.
  43.   uint16_t time = millis() >> 2;
  44.   for(uint16_t i = 0; i < LED_COUNT; i++)
  45.   {
  46.     byte x = (time >> 2) - (i << 3);
  47.     colors[i] = hsvToRgb((uint32_t)x * 359 / 256, 255, 255);
  48.   }

  49.   // Write the colors to the LED strip.
  50.   ledStrip.write(colors, LED_COUNT);

  51.   delay(10);
  52. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 14:40 | 顯示全部樓層
17--.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 14:42 | 顯示全部樓層
18.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 14:44 | 顯示全部樓層
19.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 14:45 | 顯示全部樓層
20.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 14:48 | 顯示全部樓層
21.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 16:04 | 顯示全部樓層
22.jpg
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2019-10-1 16:19 | 顯示全部樓層
23.jpg
回復(fù)

使用道具 舉報(bào)

ID:485431 發(fā)表于 2020-2-8 14:20 | 顯示全部樓層
非常經(jīng)典,謝謝
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2020-2-8 16:34 | 顯示全部樓層
891558534 發(fā)表于 2020-2-8 14:20
非常經(jīng)典,謝謝

元宵節(jié)快樂!謝謝鼓勵(lì)!
回復(fù)

使用道具 舉報(bào)

ID:780673 發(fā)表于 2020-6-22 09:37 | 顯示全部樓層
樓主的分享很有意義
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2020-10-24 15:44 | 顯示全部樓層
ssw2020 發(fā)表于 2020-6-22 09:37
樓主的分享很有意義

謝謝鼓勵(lì)
回復(fù)

使用道具 舉報(bào)

ID:871536 發(fā)表于 2020-12-31 15:36 | 顯示全部樓層
想問下一直顯示這串代碼錯(cuò)誤是因?yàn)槭裁矗?br /> Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
回復(fù)

使用道具 舉報(bào)

ID:513258 發(fā)表于 2021-1-1 15:44 | 顯示全部樓層
聽風(fēng)的賬號(hào)1111 發(fā)表于 2020-12-31 15:36
想問下一直顯示這串代碼錯(cuò)誤是因?yàn)槭裁矗?br /> Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_K ...

那個(gè)程序?具體情況請(qǐng)截個(gè)圖看看
回復(fù)

使用道具 舉報(bào)

ID:143767 發(fā)表于 2021-1-24 19:09 | 顯示全部樓層
不好意思,我剛接觸arduino,不知這個(gè)錯(cuò)誤是什么意思,怎么修改,謝謝
stray '#' in program
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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