#include <Adafruit_NeoPixel.h>  //添加ws2812库    Add the ws2812 library
#define NUMPIXELS 4             // 定义ws2812 灯数  Number of 2812 lamps
#define  RGB_PIN  A0            // 定义ws2812引脚A0  ws2812 pin definition A0 

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, RGB_PIN, NEO_GRB + NEO_KHZ800);//实例化灯对象   Creating light objects

void setup ()         //设置函数    Function initialization
{
	strip.begin();      //初始化库函数    Initialize 2812 library functions
	strip.show();
	Serial.begin(9600);
}

// 使所有RGB为指定颜色  Set all RGB to the specified color
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, color);
    strip.show();
    delay(wait);
  }
}

void loop()           //主函数    Principal function
{
  /*!
  @brief   Set a pixel's color using separate red, green and blue.
           components. If using RGBW strip, white will be set to 0.
  @param   n  Pixel index, starting from 0.
  @param   r  Red brightness, 0 = minimum (off), 255 = maximum.
  @param   g  Green brightness, 0 = minimum (off), 255 = maximum.
  @param   b  Blue brightness, 0 = minimum (off), 255 = maximum.
  strip.setPixelColor(n, strip.Color(r,g,b));
  */
    // 将所有RGB关闭
    colorWipe(strip.Color(0, 0, 0), 1); // 1mm延时
    delay(2000);    //不同颜色灯切换之间延时2000ms The delay between the switch of different color lights is 2000ms
    // 将所有RGB的颜色设置为红色  Set the color of all RGBs to red
    colorWipe(strip.Color(255, 0, 0), 1);
    delay(2000);
    // 将所有RGB的颜色设置为绿色  Set the color of all RGBs to green
    colorWipe(strip.Color(0, 255, 0), 1);
    delay(2000);
    // 将所有RGB的颜色设置为蓝色  Set the color of all RGBs to blue
    colorWipe(strip.Color(0, 0, 255), 1);
    delay(2000);
    // 将所有RGB的颜色设置为白色  Set the color of all RGBs to white
    colorWipe(strip.Color(100, 100, 100), 1);
    delay(2000);
    // 将所有RGB的颜色设置为黄色  Set the color of all RGBs to yellow
    colorWipe(strip.Color(180, 75, 0), 1);
    delay(2000);
}
































