Blynk as manual control for automation

Hello Everyone! I am having a hard time trying to accomplish something i thought would be fairly simple and im wondering if it is even possible at this point. i want my ATMEGA 2560 to run a code that ive written that monitors the state of charge on a battery and triggers certain actions depending on the battery state, my code works fine by itself. what im looking for is i also what the option to install a switch that when flipped in starts the Blynk.run(); function and allows me to control the board manually as long as the switch is flipped on but when i flip the switch off i want blynk to stop. is there a way to do this? is there not a function i can use that would be the equivalent of Blynk.stop(); or something like that? i tried putting blynk.run inside of a while loop thinking that would be the easy solution but it seems blynk.run happens even if the conditions for the while loop are not met. honestly im lost. any help would be greatly appreciated,

p.s. ive looked into using a timer, but im not exactly sure how using a timer will help me since i need it to respond to the battery voltage and not just perform functions at given times.

Since Blynk is effectively a group of libraries loaded and “running” all the time, just like any other library… you don’t just “shut it off”… just like you don’t shut off a Servo Library or LCD library, etc. when you are not actually moving a servo or displaying data to the LCD.

Running your sketch in “automatic” or “manual” mode, with or without App/Widget control/feedback, etc. all comes down to how you write your code.

1 Like

I forgot to ask you to post your code here for us to see… easier to make a suggestion or two that way :wink:

When pasting your code into a topic, please format as per this step, to make it properly visible in this forum.

Have you tried Blynk.disconnect();

You could maybe put this in an IF statement. If a certain digital pin is HIGH (your switch on), the you connect to BLYNK; Blynk.begin(auth, ssid, pass);. If it is LOW (your switch off) then disconnect from BLYNK; Blynk.disconnect();

Not certain this would work. Just an idea.