arduino蓝牙WS2812彩灯

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#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<NUMPIXELS;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<NUMPIXELS;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<NUMPIXELS;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();
        
      }
     
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值