Arduino点亮ws2812

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_35527832/article/details/79179276
先加载ws2812库文件https://github.com/adafruit/Adafruit_NeoPixel
#include <Adafruit_NeoPixel.h>
 
#define PIN 6
#define MAX_LED 8
 
#define ADD true
#define SUB false
 
int val = 0;
boolean stat = ADD;
 
// Parameter 1 = ws2811级联数量
// Parameter 2 = arduino PIN
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );

void setup()
{
  strip.begin();           //初始化Adafruit_NeoPixel;
  strip.show();           //显示所有LED为关状态;
}

void loop()
{
  uint8_t i,a=0;                                        
  uint32_t color = strip.Color(0, 100, 255);         //选择所显示的颜色
  while(a<10)
  {
      for(i=0;i<9;i++)
      {
        if(i==a) strip.setPixelColor(i, color);     //第几个LED点亮;
        else strip.setPixelColor(i, 0);             //使其他LED全灭;
      }
       strip.show();                                //是LED显示所选的颜色;
       delay(20);                                   //延时20ms;
       a++;                                         
  }
}

展开阅读全文

没有更多推荐了,返回首页