arduino蓝牙WS2812彩灯

#include
#ifdef __AVR__
  #include
#endif

#define PIN            6

#define NUMPIXELS      5
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500; 
int delayval1 = 1; 

void setup()
{
  #if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // 设置波特率为 38400
  Serial.begin(9600);
  
   pixels.begin(); // This initializes the NeoPixel library.
}

void hong() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

  for(int i=0;i

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(100,0,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }
}

void bian1()
{   
  
  
    for(int i=0;i     {
       pixels.setPixelColor(i, pixels.Color(150,0,0)); 
       pixels.show();
      delay(delayval);
       pixels.setPixelColor(i, pixels.Color(0,150,0)); 
       pixels.show();
      delay(delayval);
    }
 
  
}
void off()
{
    for(int i=0;i     {
       pixels.setPixelColor(i, pixels.Color(0,0,0)); 
       pixels.show();
      delay(delayval1);

  }
}
void loop()
{
  while(Serial.available())
  {
    char c=Serial.read();
      if(c=='2')
     {
       Serial.write("关");
       off();
     } 
      if(c=='1')
      {
        Serial.write("变");
        
      
        bian1();
        
      }
     
  }
}

 

你可能感兴趣的:(arduino蓝牙WS2812彩灯)