看看这样行不?
- #include <Adafruit_NeoPixel.h>
- /*
- 【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
- 实验一百三十一:24位 WS2812 5050 RGB LED 内置全彩驱动彩灯 圆形开发板
- 项目三:使用红色、绿色和蓝色三种参数将任何LED设置为任何颜色
- Module UNO
- VCC —— 5V
- GND —— GND
- DI —— D6
- */
- #include <FastLED.h>
- #define LED_PIN 6
- #define NUM_LEDS 24
- CRGB leds[NUM_LEDS];
- void setup() {
- FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
- }
- void loop() {
- unsigned int i;
- leds[0] = CRGB(255, 0, 0);
- FastLED.show();
- delay(500);
- leds[1] = CRGB(0, 255, 0);
- FastLED.show();
- delay(500);
- leds[2] = CRGB(0, 0, 255);
- FastLED.show();
- delay(500);
- leds[3] = CRGB(150, 0, 255);
- FastLED.show();
- delay(500);
- leds[4] = CRGB(255, 200, 20);
- FastLED.show();
- delay(500);
- leds[5] = CRGB(85, 60, 180);
- FastLED.show();
- delay(500);
- leds[6] = CRGB(50, 255, 20);
- FastLED.show();
- delay(500);
- leds[7] = CRGB(255, 0, 0);
- FastLED.show();
- delay(500);
- leds[8] = CRGB(0, 255, 0);
- FastLED.show();
- delay(500);
- leds[9] = CRGB(0, 0, 255);
- FastLED.show();
- delay(500);
-
- for(i=10;i<20;i++)
- {
- leds[i] = CRGB(0, 0, 0);
- }
- FastLED.show();
-
-
- delay(1000);
- for(i=0;i<10;i++)
- {
- leds[i] = CRGB(0, 0, 0);
- }
- FastLED.show();
-
- leds[10] = CRGB(255, 0, 0);
- FastLED.show();
- delay(500);
- leds[11] = CRGB(0, 255, 0);
- FastLED.show();
- delay(500);
- leds[12] = CRGB(0, 0, 255);
- FastLED.show();
- delay(500);
- leds[13] = CRGB(150, 0, 255);
- FastLED.show();
- delay(500);
- leds[14] = CRGB(255, 200, 20);
- FastLED.show();
- delay(500);
- leds[15] = CRGB(85, 60, 180);
- FastLED.show();
- delay(500);
- leds[16] = CRGB(50, 255, 20);
- FastLED.show();
- delay(500);
- leds[17] = CRGB(255, 0, 0);
- FastLED.show();
- delay(500);
- leds[18] = CRGB(0, 255, 0);
- FastLED.show();
- delay(500);
- leds[19] = CRGB(0, 0, 255);
- FastLED.show();
- delay(1000);
-
- }
复制代码 |