小白求助blinker接入WS2812-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 422|回复: 0

[未解决] 小白求助blinker接入WS2812

[复制链接]
发表于 2022-4-5 16:28 | 显示全部楼层 |阅读模式
求助,我原本想用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]
以上是我的代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 09:49 , Processed in 0.066587 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表