|
求助,我原本想用blinker接入WS2812做氛围灯,用fastled驱动ws2812结果发现想要连续显示一个模式就要一直点我设置相应模式按钮,就像放ppt一样,请问给位大神,怎么解决[md]#define BLINKER_WIFI
#include <Blinker.h>
#include <FastLED.h>
#define NUM_LEDS 6 //灯的个数
#define DATA_PIN 4 //引脚
#define LED_TYPE WS2812 //LED带的型号
#define COLOR_ORDER GRB //RGB排序
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS]; //建立LED光带
uint8_t gCurrentPatternNumber = 0;
uint8_t gHue = 0;
uint8_t startIndex;
char auth[] = "a0193081acd4";
char ssid[] = "万豪门窗";
char pswd[] = "lihe147258369";
//建立组件
BlinkerButton Button1("a");//照明
BlinkerButton Button2("model1");//睡眠
BlinkerButton Button3("model2");//循环
BlinkerButton Button4("b");//流水
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ",state);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
fill_solid(leds, NUM_LEDS, CRGB::White);
}
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ",state);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void button3_callback(const String & state)
{
BLINKER_LOG("get button state: ",state);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < NUM_LEDS; i++) {
leds = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
}
}
void button4_callback(const String & state)
{
BLINKER_LOG("get button state: ",state);
fill_solid(leds,NUM_LEDS, CRGB::Black);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
//初始化blinker
Blinker.begin(auth,ssid,pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
//初始化灯带
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
EVERY_N_MILLISECONDS( 20 ) { gHue++; };
FastLED.delay(1000/FRAMES_PER_SECOND);
digitalWrite(LED_BUILTIN, HIGH);
Blinker.run();
FastLED.show();
}[/md]
以上是我的代码 |
|