能帮我看下,问题出在哪吗?
提示Arduino:1.8.13 (Windows 7), 开发板:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
E:\单片机\氛围灯\1.25\1.25\1.251\1.251.ino: In function 'void tab1_callback(uint8_t)':
1.251:45:13: error: 'Mode1' was not declared in this scope
1.251:53:13: error: 'Mode3' was not declared in this scope
E:\单片机\氛围灯\1.25\1.25\1.251\1.251.ino: In function 'void button1_callback(const String&)':
1.251:138:50: error: 'SET_RGB' was not declared in this scope
1.251:139:27: error: 'SET_RGB' was not declared in this scope
E:\单片机\氛围灯\1.25\1.25\1.251\1.251.ino: In function 'void Mode0(uint32_t, int)':
1.251:143:18: error: 'strip' was not declared in this scope
1.251:149:37: error: a function-definition is not allowed here before '{' token
1.251:355:1: error: expected '}' at end of input
exit status 1
'Mode1' was not declared in this scope
在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。
#include <Adafruit_NeoPixel.h>
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT
#include <Blinker.h>
#include <Adafruit_NeoPixel.h>
char auth[] = "64e4f6335177";
char ssid[] = "LYH";
char pswd[] = "lyh788799";
bool tab[4] = { false };
bool modestate[4] = { false }; //工作模式选项卡
bool AutoBit = false; //判断手动模式是否有效
bool SingleAdjust = false; //判断逐个调节是否有效
int LEDserial = 15; //
int Offset = 60; //灯珠整体移动若干单位
#define PIN 15 // DIN PIN (GPIO15, D8)
#define NUMPIXELS 60 // Number of you led
#define RGB_1 "RGBKey"
#define Tab_1 "tab-mode"
#define Number_1 "LEDNum"
#define Number_2 "LED_R"
#define Number_3 "LED_G"
#define Number_4 "LED_B"
BlinkerRGB WS2812(RGB_1);
BlinkerButton Button1("key");
BlinkerTab Tab1(Tab_1);//定义数据结构
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
BlinkerNumber Number1 (Number_1);
BlinkerNumber Number2 (Number_2);
BlinkerNumber Number3 (Number_3);
BlinkerNumber Number4 (Number_4); //*************************************************************//选项卡触发函数
void tab1_callback(uint8_t tab_set) { //BLINKER_LOG("get tab set: ", tab_set);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
switch (tab_set) {
case BLINKER_CMD_TAB_0 :
tab[0] = true; //BLINKER_LOG("tab 0 set");
AutoBit = !AutoBit; //手动位取反
break;
case BLINKER_CMD_TAB_1 :
tab[1] = true; //BLINKER_LOG("tab 1 set");
Mode1();//开启Mode1,
break;
case BLINKER_CMD_TAB_2 :
tab[2] = true; //BLINKER_LOG("tab 2 set");
SingleAdjust = !SingleAdjust; //开启Mode2,
break;
case BLINKER_CMD_TAB_3 :
tab[3] = true; //BLINKER_LOG("tab 3 set");
Mode3();//开启Mode3,
break;
case BLINKER_CMD_TAB_4 :
tab[4] = true; //BLINKER_LOG("tab 4 set");
break;
default:
break;
}
}
void tab1_feedback() {
for (uint8_t num = 0; num < 5; num++) {
if (tab[num]) {
Tab1.tab(num);
tab[num] = false;
}
}
Tab1.print();
}
/***************配网函数**************/
bool WIFI_Status = true;
void smartConfig()//配网函数
{
WiFi.mode(WIFI_STA);
Serial.println("\r\nWait for Smartconfig...");
WiFi.beginSmartConfig();//等待手机端发出的用户名与密码
while (1)
{
Serial.print(".");
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
if (WiFi.smartConfigDone())//退出等待
{
Serial.println("SmartConfig Success");
Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str());
Serial.printf("PSW:%s\r\n", WiFi.psk().c_str());
break;
}
}
}
void WIFI_Set()//
{
//Serial.println("\r\n正在连接");
int count = 0;
while(WiFi.status()!=WL_CONNECTED)
{
if(WIFI_Status)
{
Serial.print(".");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
count++;
if(count>=5)//5s
{
WIFI_Status = false;
Serial.println("WiFi连接失败,请用手机进行配网");
}
}
else
{
smartConfig(); //微信智能配网
}
}
/* Serial.println("连接成功");
Serial.print("IP:");
Serial.println(WiFi.localIP());*/
}
int counter = 0;
int LED_R=0,LED_G=0,LED_B=0,LED_Bright=255;// RGB和亮度
bool LED_Flag = false;
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
Blinker.print(state);
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
LED_Flag = !LED_Flag;
if(LED_Flag) SET_RGB(255,255,255,LED_Bright);
else SET_RGB(0,0,0,0);
}
void Mode0(uint32_t color, int wait){
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
void Mode1(uint32_t color, int wait){
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
void Mode2(int wait){
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
// Offset pixel hue by an amount to make one full revolution of the
// color wheel (range of 65536) along the length of the strip
// (strip.numPixels() steps):
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
// optionally add saturation and value (brightness) (each 0 to 255).
// Here we're using just the single-argument hue variant. The result
// is passed through strip.gamma32() to provide 'truer' colors
// before assigning to each pixel:
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void Mode3(int wait){
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for(int a=0; a<30; a++) { // Repeat 30 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in increments of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter=counter;
Number1.print(counter);
}
void SET_RGB(int R,int G,int B,int bright)
{
for (uint16_t i = 0; i < NUMPIXELS; i++) //把灯条变色
{
pixels.setPixelColor(i,R,G,B);
}
pixels.setBrightness(bright);//亮度
pixels.show(); //送出显示
}
//APP RGB颜色设置回调
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);
LED_Bright = bright_value;
SET_RGB(r_value,g_value,b_value,LED_Bright);
}
//小爱电源类回调
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
//digitalWrite(LED_BUILTIN, LOW);
SET_RGB(255,255,255,255);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_OFF) {
//digitalWrite(LED_BUILTIN, HIGH);
SET_RGB(255,255,255,0);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
}
}
//小爱设置颜色回调
void miotColor(int32_t color)
{
BLINKER_LOG("need set color: ", color);
int colorR,colorG,colorB;
colorR = color >> 16 & 0xFF;
colorG = color >> 8 & 0xFF;
colorB = color & 0xFF;
BLINKER_LOG("colorR: ", colorR, ", colorG: ", colorG, ", colorB: ", colorB);
SET_RGB(colorR,colorG,colorB,LED_Bright);
//pixelShow();
BlinkerMIOT.color(color);//反馈小爱控制状态
BlinkerMIOT.print();
}
//小爱调亮度回调
void miotBright(const String & bright)
{
BLINKER_LOG("need set brightness: ", bright);
int colorW = bright.toInt();
BLINKER_LOG("now set brightness: ", colorW);
LED_Bright = colorW;
SET_RGB(LED_R,LED_G,LED_B,LED_Bright);
Serial.printf("亮度调节中...%d",colorW);
BlinkerMIOT.brightness(colorW);//反馈小爱控制状态
BlinkerMIOT.print();
}
void setup() {
// 初始化串口
Serial.begin(115200);
pixels.begin();//WS2812初始化
pixels.show();
pinMode(LED_BUILTIN, OUTPUT);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
Serial.begin(115200); BLINKER_DEBUG.stream(Serial); Blinker.attachData(dataRead); pinMode(LED_BUILTIN, OUTPUT);//引脚设置为输出模式
digitalWrite(LED_BUILTIN, LOW); Blinker.begin(auth, ssid, pswd); pixels.begin();//开启pixel对ws2812输出
WS2812.attach(ws2812_callback);
Tab1.attach(tab1_callback,
tab1_feedback);
}
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
WIFI_Set();
// 初始化blinker
Blinker.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());
Blinker.attachData(dataRead);//如果没有被绑定的组件被触发就执行这个回调
Button1.attach(button1_callback);//Button1这个组件被触发就执行这个回调
RGB1.attach(rgb1_callback);//注册调节颜色的回调函数
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachColor(miotColor);//小爱调节颜色
BlinkerMIOT.attachBrightness(miotBright);//小爱调节RGB亮度
}
void loop()
{
// Fill along the length of the strip in various colors...
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color( 0, 255, 0), 50); // Green
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
// Do a theater marquee effect in various colors...
theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness
theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness
rainbow(10); // Flowing rainbow cycle along the whole strip
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
}
Blinker.run();
}
|