|
上图是BLINKER官方示例里的图片。
图中的控制效果,灯的变化和手指滑动是同步的。
我自己做出来的效果是手指滑到某一个色,放开手指了,灯才变成那个色,滑动过程中,灯不变色。
怎么解决?我加什么代码?
以下是我找到的示例代码:
========================================================
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "**********";
char ssid[] = "***********";
char pswd[] = "**********";
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 0
#define NUMPIXELS 1
#define Number_1 "LED_R"
#define Number_2 "LED_G"
#define Number_3 "LED_B"
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
BlinkerNumber Number1 (Number_1);
BlinkerNumber Number2 (Number_2);
BlinkerNumber Number3 (Number_3);
#define RGB_1 "RGBKey"
BlinkerRGB RGB1(RGB_1);
void rgb1_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
BLINKER_LOG("R value: ", r_value);
BLINKER_LOG("G value: ", g_value);
BLINKER_LOG("B value: ", b_value);
BLINKER_LOG("Rrightness value: ", bright_value);
uint8_t colorR = map(r_value, 0, 255, 0, bright_value);
uint8_t colorG = map(g_value, 0, 255, 0, bright_value);
uint8_t colorB = map(b_value, 0, 255, 0, bright_value);
Number1.print(r_value);
Number2.print(g_value);
Number3.print(b_value);
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, pixels.Color(colorR,colorG,colorB));
pixels.show();
}
}
void setup()
{
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
pixels.begin();
RGB1.attach(rgb1_callback);
}
void loop()
{
Blinker.run();
}
|
|