I'm seeing the same warning / problem when trying to get the Blynk library to blink an LED within the app when I push a physical button on the Particle. The weird thing is -- everything works fine if I inline the "toggleLed" function, so I'm not sure if my C++ passing by reference semantics are to blame.
Can you please take a look? I think my next stops might need to by the Blynk forums / github, unless you can see something obviously wrong with my code:
//#pragma SPARK_NO_PREPROCESSOR
//#include "application.h"
#include "clickButton/clickButton.h"
#include "blynk/blynk.h"
//Class WidgetLED; //pre-defining didn't work
char auth[] = "12345etc";
ClickButton b1(A0);
WidgetLED led1(V0);
//void toggleLed(WidgetLED&);
void toggleLed(const WidgetLED& myled) {
if(myled.getValue()) {
myled.off();
} else {
myled.on();
}
}
void setup() {
pinMode(A0, INPUT_PULLUP);
delay(1000);
Blynk.begin(auth);
}
void loop() {
Blynk.run();
if (b1.clicks > 0) toggleLed(&led1);
}
The error I see when verifying is:
In file included from blynk/BlynkParticle.h:16:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from blynk_test.cpp:5:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
#warning "analogInputToDigitalPin not defined => Named analog pins will not work"
^
blynk_test.cpp: In function 'void toggleLed(const WidgetLED&)':
blynk_test.cpp:17:19: error: passing 'const WidgetLED' as 'this' argument of 'void WidgetLED::off()' discards qualifiers [-fpermissive]
myled.off();
^
blynk_test.cpp:19:18: error: passing 'const WidgetLED' as 'this' argument of 'void WidgetLED::on()' discards qualifiers [-fpermissive]
myled.on();
^
blynk_test.cpp: In function 'void loop()':
blynk_test.cpp:31:39: error: invalid user-defined conversion from 'WidgetLED*' to 'const WidgetLED&' [-fpermissive]
if (b1.clicks > 0) toggleLed(&led1);
^
In file included from blynk/BlynkWidgets.h:10:0,
from blynk/BlynkSimpleParticle.h:19,
from blynk/blynk.h:2,
from blynk_test.cpp:5:
blynk/WidgetLED.h:18:2: note: candidate is: WidgetLED::WidgetLED(uint8_t)
WidgetLED(uint8_t pin) : mPin(pin) {}
^
blynk/WidgetLED.h:18:2: note: no known conversion for argument 1 from 'WidgetLED*' to 'uint8_t {aka unsigned char}'
blynk_test.cpp:31:39: error: invalid conversion from 'WidgetLED*' to 'uint8_t {aka unsigned char}' [-fpermissive]
if (b1.clicks > 0) toggleLed(&led1);
^
In file included from blynk/BlynkWidgets.h:10:0,
from blynk/BlynkSimpleParticle.h:19,
from blynk/blynk.h:2,
from blynk_test.cpp:5:
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/WidgetLED.h:18:2: error: initializing argument 1 of 'WidgetLED::WidgetLED(uint8_t)' [-fpermissive]
WidgetLED(uint8_t pin) : mPin(pin) {}
^
make[1]: *** [../build/target/user/platform-6blynk_test.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.
Is there something about the definition of this class that prevents passing instance references of it to a function? Or (more likely probably) am I doing it wrong? Thank you for your help.
Edit: "Works fine when the function is inlined" just means that it compiles and uploads to the photon. Still can't get Blynk LED widget to light up in the app when I click a button attached to the Photon.