#include <Adafruit_NeoPixel.h>#define PIN 2#define NUMPIXELS 24#define BRIGHTNESS 50#define DELAYVAL 500Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);int MODE = 0; // 模式void setup() { strip.setBrightness(BRIGHTNESS); // 初始化Adafruit_NeoPixel库 strip.begin(); // 初始化时关闭所有LED strip.show(); }void loop() { switch(MODE){ case 0: RunningWater(); break; case 1: colorWipe(strip.Color(150, 150, 150), 50); break;// BlueWite case 2: rainbowCycle(1); case 3: rainbow(50); case 4: rainbowCycle(1); } MODE++; if(MODE == 4){ MODE = 0; }}/** * 模式: 颜色擦除 */void colorWipe(uint32_t c, uint8_t wait) { strip.clear(); for (uint16_t i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); }}/** * 彩虹呼吸 */void rainbow(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256; j++) { for (i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i + j) & 255 )); } strip.show(); delay(wait); }}/** * 彩虹呼吸-旋转 */void rainbowCycle(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel for (i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); }}/** * 走马灯 */void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show(); delay(wait); for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } }}/** * 走马灯-彩虹 */void theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip.show(); delay(wait); for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } }}uint32_t Wheel(byte WheelPos) { if (WheelPos < 85) { return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if (WheelPos < 170) { WheelPos -= 85; return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); }}