Arduino点亮ws2812
先加载ws2812库文件https://github.com/adafruit/Adafruit_NeoPixel#include#define PIN 6#define MAX_LED 8#define ADD true#define SUB falseint val = 0;boolean stat = ADD;// Parameter 1 = ws2811级联
文章共199字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
先加载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++;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)