Mr. Pete
Of course, I wouldn’t be offended if you wrote the entire code for me for flashing two let diodes
(one button, one LED / second button, second LED)
(blinking)
Mr. Pete
Of course, I wouldn’t be offended if you wrote the entire code for me for flashing two let diodes
(one button, one LED / second button, second LED)
(blinking)
recently (today) I saw tutorials for the millis function which are supposedly better than delay… maybe if I watch 500 tutorials, I will know how to use it… if at the moment I can’t modify the code you gave me, I could make two blinking LEDs under the buttons.
Hi, I suggest you go through the Example Browser first. It will help you understand a bit more how to work with Blynk.
See link below.
https://examples.blynk.cc/
Rather than using the Millis functionality, you should use BlynkTimer, which is what I did in the original example.
The part you’re missing is that you’re missing in your modifications to that example is your understanding of how it works…
The timer calls the toggle_led
function once every 500ms.
The toggle_led
function checks the status of a variable called blynk_led_switch
and if it is 1 then it will read the current status of the LED and invert (toggle) it.
The blynk_led_switch
variable is changed by the BLYNK_WRITE(V1)
function, so it reflects the status of the switch widget attached to datastream V1.
If you want to have other LEDs blinking at this same 500ms frequency, then you just need another variable like blynk_led_switch
to reflect the status of your additional widget/virtual datastream, and change that variable in the corresponding BLYNK_WRITE(vPin)
function (the bit that says “some code in here”). You then need to duplicate the code that is in the toggle_led
function relating to ‘blynk_led_switch` and your GPIO 2 LED and change it so that it relates to your new variable and alternative GPIO.
Pete.
Recently, about a week ago, I modified it, thinking that the one below would work… unfortunately, no matter what button I press, the two LEDs flash. and basically I don’t know what to do next… what to modify and change to achieve my goal. Of course, you can write such a sketch with your eyes closed, but someone who has no knowledge of C++ is blind. this whole code is like egyptian hieroglyphs to me.
Probably if I don’t see with my own eyes what such code looks like, I will never figure it out…
Currently, my delay code is bad, but it works… well, the problem is actually with blocking the device while executing the delay, so for now, I may use it if I don’t know what the timer code you gave me as an example should look like.
#define BLYNK_TEMPLATE_ID "bllblblblbl"
#define BLYNK_TEMPLATE_NAME "blblblblb"
#define BLYNK_AUTH_TOKEN "blblblbllb"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
char ssid[] = "blblbblbb";
char pass[] = "blblblblblb";
int blynk_led_switch = 0;
BlynkTimer timer;
void setup()
{
// Debug console
Serial.begin(74880);
pinMode(16,OUTPUT); // Onboard LED of the Wemos D1 mini is connected to GPIO16
pinMode(4,OUTPUT); // Onboard LED of the Wemos D1 mini is connected to GPIO4
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(500, toggle_led); // timer to toggle the LED every 500ms
}
void loop()
{
Blynk.run();
timer.run();
}
void toggle_led()
{
if(blynk_led_switch == 1)
{
int current_state = digitalRead(16);
digitalWrite(16,!current_state);
}
else
{
digitalWrite(16, LOW); // turn the LED off
}
if(blynk_led_switch == 1)
{
int current_state = digitalRead(4);
digitalWrite(4,!current_state);
}
else
{
digitalWrite(4, LOW); // turn the LED off
}
}
BLYNK_CONNECTED() // Triggered whne the device connects or re-connects to Blynk
{
Blynk.syncVirtual(V1); // Get the state of the V1 widget on startup
Blynk.syncVirtual(V0); // Get the state of the V0 widget on startup
}
BLYNK_WRITE(V1) // Triggered when the switch widget attache to V1 changes state
{
blynk_led_switch = param.asInt();
}
BLYNK_WRITE(V0) // Triggered when the switch widget attache to V0 changes state
{
blynk_led_switch = param.asInt();
}
You are using the blynk_led_switch
variable in both BLYNK_WRITE(vPin)
functions.
Had you taken the time to read my previous post, you’d haves seen that I explained that…
and…
You haven’t done this.
I then went on to say…
You’ve duplicated the code, and changed the GPIO pin, but you are still doing the logical if
test on blynk_led_switch
in both cases.
If you wnat two switch widgets that work 8ndependent,y then you need TWO VARIABLES not one.
And guess what - this shouldn’t be news to you because I also said the same thing three weeks ago…
Pete.
Tnx… i know this side
Mr. Pete
ok, maybe in a different way:
What should such a sketch look like if you were to write it?
because I have a feeling that we can write about it forever and I will still be stupid to understand it
(2 led, 2 buttons…( 1 button turn on and turn off led) (second button, turn on and turn off led)
I’m not going to get sucked into writing more code for you, as you started-off off saying that you needed a simple example to flash one LED, which is what I gave you.
I’ve also given you lots of pointers in the form of in-code documentation and explanations about how the code works and what changes you’d need to make to add more features.
That’s all you’re getting from me I’m afraid.
Pete.
Mr. Pete, if you don’t give me the code, I won’t send you a Christmas postcard (kidding, of course).
ok, no problem… maybe with time I will be able to deal with it somehow… but anyway, thank you for your help.