I read that but didn’t understand how I can use this exactly.
I did my last program more than 20 years ago
Thats why I need further information.
To be clear I understand Virtual Pins but lets say I got a loop doing some fancy LED lighting. I then would like my arduino to stop the routine and do sone other once such virtual pin gets updated.
So I don’t need the BLYNK-RUN() at all when using BLYNK_WRITE() ?
BUT
Let’s say i got a loop doing something for one minute. Is there a way to call a interrupt function when a virtual pin is set or is the way to include such if statement in this loop?
No, you always need blynk.run(). That is where the Blynk magic happens.
An interupt is a hardware thing. I think Pin2 on the Arduino can handle interupts, but in most cases it is enough to have a timer. The ideal loop() looks like this:
No, that is not possible as far as I know because a virtual pin is software and and interrupt is a hardware thing. You have to stop the cpu from doing what it’s doing and that can’t be accomplished with virtual pins.
What is it you want to do anyway? We may be able to give you some hints to get it working like you want
You cannot directly interrupt a virtual pin.
Instead of interrupts you can use polling. Suppose that your system has three lighting modes, a 250 ms blinking, 500 ms blinking and 1 sec blinking and you want each mode to be running until you stop it and try out another one.
Define three different functions each with the functionality mentioned above and in each function check for status of the virtual pins associated with that lighting mode on the Blynk application(USE A SWITCH IN BLYNK APPLICATION AND NOT A PUSH).
Now, the question is how and when will you check this.
eg:
void blink250()
{
int num=1;
while(1)
{
digitalWrite(yourLEDpin,“HIGH”);
delay(250);
BLYNK_WRITE(VirtualpinAssociatedWithThatLightingMode)
{
num=param.asInt() //according to me it will be 0 for a LOW value of the Switch
if(num==0)
{
loop();
}
}
digitalWrite(yourLEDpin,“LOW”);
}
What you do here is, after every blink you check the status of the pin associated with that mode on the blynk app. If it is low you go back to the loop.
In the loop continuously check for the status of all the three virtual pins in the same manner and call the three functions accordingly.
I am not sure if I have understood your problem correctly and whether the solution i gave you will work for you but i definitely did try my best.
@vshymanskyy please correct me for this if it is wrong
num=param.asInt() //according to me it will be 0 for a LOW value of the Switch
See, you have to understand that what you are using for your project is a micro controller based board and not a microprocessor based board like Intel Gallileo. You cannot multitask with it.
What you want can only be possible if we use 10 external interrupts which is out of question because no micro controller provides 10 external interrupt pins.
In fact, this whole idea cannot work with the concept of interrupts.
If at all you want to use 10 Push Buttons I suggest use two Arduino Boards, one to continuously poll your input on the Blynk app and the other to carry out the functionalities you want.
Then workout some logic to control the latter with the first board.
Based on var cycleNr (you probably need that as a global var) you can change modes in another sub routine which is called for example every 250ms. That should be short enough to do it without notable delay.
The SimpleTimer is not an interrupt, it just runs things every x-period. Interrupts, as the name says, interrupts the CPU clock cycles. I still don’t see the need for using a real interrupt using blynk since it’s so blazingly fast using it’s own code.
I think my solution should work fine without using interrupts. They are difficult to handle anyway (in a good way that is).
@Gorkde there is a heartbeat timeout set at between 5 and 10 seconds that Blynk looks for from your device. Your device may try to reconnect if it misses the heartbeat but then again it might not. A second or two is probably ok but I wouldn’t want to go much beyond this.