{
if (Blynk.connected()) {
digitalWrite(wifists, HIGH);//turn on wifi status led if device isconnected to internet
} else {
digitalWrite(wifists, LOW);
}
}
If you had have answered it correctly then you would have said that the device MUST be connected to the Blynk server for BLYNK_WRITE(V0), so putting this test into BLYNK_WRITE(V0) is a total waste of time…
Because Blynk.connected will ALWAYS be true when BLYNK_WRITE(V0) executes.
As I said before, but you chose to ignore, when this piece of code was in your void loop…
Giving your functions names that describe what they do is always a good idea. This function isn’t sending data to Blynk, so calling it sendData isn’t a great idea.
You have one BlynkTimer object declared, called ledtimer…
But you are calling this BlynkTimer object and the now non-existent BlynkTimer object called timer in your void loop…
This will cause a compiler error (unless you’re running a very early version of the Edgent example).
If you’d actually bothered to read my timers tutorial you would have seen that each BlynkTimer object can support upto 16 timers - that’s 16 separate timer declarations in void setup like this…
So using a generic name for your timer object - such as timer - makes more sense, as that one BlynkTimer object can be used to call functions which perform very different functions, not just switching the state of an LED.
I think I’ll step back from further comments on your posts, other than ones that require moderator input, as I find your unwillingness to read information that is provided to you at odds with my approach.
Just updated the library an the code compiles fine.
I thought that using pin 2 would b a good idea as the onboard led is connected to pin 2 and it would be easier to see th connection status without the need of hooking up a seperate LED.
is it possible to change
the pin in the settings tab?
You mean in the blynk. cloud dashboard;
data type as integer,
min value= 500,
max value=5000
default value=750
should there be a led hoooked to whichever pin i connect the BOARD_LED_PIN to?
i tried only integer and not long int. should i try long int too?
from what i understood,i dont think long int will be needed in this case as im using values from 500 to 5000
If you are working with numbers that are within the range of int, then using int instead of long int should not cause any issues. However, if you are working with numbers that are larger than the range of int, then using int instead of long int could cause overflow issues, where the value stored in the variable exceeds the maximum representable value.
I checked the settings.h tab but couldnt find this line of code
btw…how do i use this code for multiple buttons and relays (3 buttons and relays while using the same slider as the timeout value for all buttons and relays)
Heres my code
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
const int wifists=2;
int slider;
#include "BlynkEdgent.h"
#define USE_NODE_MCU_BOARD
BLYNK_WRITE(V7)
{
slider = param.asInt();
}
BLYNK_WRITE(V0)
{
int pin = param.asInt();
if (param.asInt()){
digitalWrite(16, LOW);
timer.setTimeout(slider, [] () {digitalWrite(16, HIGH);Blynk.virtualWrite(V0,LOW);} );
} else {
digitalWrite(16, HIGH);
}
}
void setup() {
Serial.begin(115200);
delay(100);
pinMode(16, OUTPUT);
pinMode(wifists, OUTPUT);
digitalWrite(16,HIGH);
BlynkEdgent.begin();
timer.setInterval(1000L, connect);
}
void connect()
{
{
if (Blynk.connected()) {
digitalWrite(wifists, HIGH);//turn on wifi status led if device isconnected to internet
} else {
digitalWrite(wifists, LOW);
}
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V7);
}
void loop() {
BlynkEdgent.run();
timer.run();
}