Hi everyone, just play with Blynk with few days,
I would like to click a button to turn on a led, and a led status will on to show the led is on.
I am success to turn on One Led, but fail to turn on 2 Leds with the error message
'expected unqualified-id before ')' token'
Below are my codes, any problems I missed?
const int btnPin1 = 14;
const int btnPin2 = 12;
WidgetLED() led0(V0);
WidgetLED() led1(V1);
BlynkTimer timer;
// V3 LED Widget represents the physical button state
boolean btnState1 = false;
boolean btnState2 = false;
void buttonLedWidget()
{
// Read button
boolean isPressed1 = (digitalRead(led0) == LOW);
// If state has changed...
if (isPressed1 != btnState1) {
if (isPressed1) {
led0.off();
} else {
led0.on();
}
btnState1 = isPressed1;
}
boolean isPressed2 = (digitalRead(led1) == LOW);
// If state has changed...
if (isPressed2 != btnState2) {
if (isPressed2) {
led1.off();
} else {
led1.on();
}
btnState2 = isPressed2;
}
}
void setup()
{
// Debug console
Serial.begin(116200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup physical button pin (active low)
pinMode(btnPin1, INPUT_PULLUP);
pinMode(btnPin2, INPUT_PULLUP);
while (Blynk.connect() == false) {
// Wait until connected
}
timer.setInterval(500L, buttonLedWidget);
}
void loop()
{
Blynk.run();
timer.run();
}
Please read How to use the forum. But the summary here:
- Use code tags
- Post the COMPLETE error. Because it DOES point to exactly the location the error occurred
Please use the code-button (</>, most-left button) to post your code. This way it is much easier to read and to provide help.
WidgetLED() led0(V0);
WidgetLED() led1(V1);
This is not valid code. If you are trying to instanciate a WidgetLED, loose the parenthesis after the class name.
Furthermore, I see no includes in your code. How is the compiler supposed to know about the types WidgetLED, BlynkTimer and Blynk?
void setup()
{
// Debug console
Serial.begin(116200);
Blynk.begin(auth, ssid, pass);
}
I don't see any variables named auth, ssid or pass.
boolean isPressed1 = (digitalRead(led0) == LOW);
digitalRead accepts a pin number, to read from. You are passing an instance of WidgetLED, this will not work!
LightuC:
Please use the code-button (</>, most-left button) to post your code. This way it is much easier to read and to provide help.
WidgetLED() led0(V0);
WidgetLED() led1(V1);
This is not valid code. If you are trying to instanciate a WidgetLED, loose the parenthesis after the class name.
Furthermore, I see no includes in your code. How is the compiler supposed to know about the types *WidgetLED*, *BlynkTimer* and *Blynk*?
void setup()
{
// Debug console
Serial.begin(116200);
Blynk.begin(auth, ssid, pass);
}
I don't see any variables named auth, ssid or pass.
boolean isPressed1 = (digitalRead(led0) == LOW);
digitalRead accepts a pin number, to read from. You are passing an instance of WidgetLED, this will not work!
I just try the example code from the example library and it is success for one led.
LED example
So I modify the code like above to turn on with 2 leds, but the error is occured.
Thanks for applying code tags.
But as LightuC, your code is incomplete. This is a free forum for help to learn how to program. Don't make us have to search to complete your code 
Also, go over it again and check the differences between your code and the example. And yes, a compiler is picky about random (){}etc 