|
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define KEYPIN D3
#define PIN D2
#define NUMPIXELS 16
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define RGB_1 "RGBKey"
void KeyRGB();
BlinkerRGB WS2812(RGB_1);
uint8_t Key_flag=0,Key=0;
uint8_t R=0,G=0,B=0,bright=0;
void ws2812_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);
R=r_value;
G=g_value;
B=b_value;
bright=bright_value;
Key=1;
pixels.setBrightness(bright_value);
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, r_value, g_value, b_value);
}
pixels.show();
for(int i=2500;i<=2503;i++)
{
EEPROM.write(i, 0);//储存更新参数
}
delay(5);
EEPROM.commit();
EEPROM.write(2500, 100);//储存更新参数
delay(5);
EEPROM.write(2501, 100);
delay(5);
EEPROM.write(2502, 100);
delay(5);
EEPROM.write(2503, 100);
delay(5);
EEPROM.commit();
delay(5);
R=EEPROM.read(2500);
G=EEPROM.read(2501);
B=EEPROM.read(2502);
bright=EEPROM.read(2503);
delay(5);
BLINKER_LOG("R value: ", R);
BLINKER_LOG("G value: ", G);
BLINKER_LOG("B value: ", B);
BLINKER_LOG("Rrightness value: ", bright);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
EEPROM.begin(4096);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(KEYPIN, INPUT);
Blinker.begin(auth);
//Blinker.attachData(dataRead);
//Blinker.attachHeartbeat(heartbeat);//设备建立连接后app会立刻发送心跳包, 此后每30s-60会发送一次心跳包
pixels.begin();
WS2812.attach(ws2812_callback);
}
void KeyRGB()
{
if((digitalRead(KEYPIN)==0)&&(Key_flag==0))
{
delay(10);
if((digitalRead(KEYPIN)==0)&&(Key_flag==0))
{
Key_flag=1;
if(Key==1)
{
pixels.setBrightness(0);
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, R, G, B);
}
pixels.show();
Key=0;
}
else
{
Key=1;
pixels.setBrightness(bright);
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, R, G, B);
}
pixels.show();
}
}
}
if((digitalRead(KEYPIN)!=0)&&(Key_flag==1))
Key_flag=0;
}
void loop()
{
Blinker.run();
KeyRGB();
}
读到的数据全是零,哪位大佬帮忙看一下
|
|