BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk_Write to enter and break a loop

#1

I am new to Arduino and blynk. I was working on the automated cloth line with blynk as my mobile application and I got it partially working. I am using virtual pin to enter the loop which is working perfectly fine. But upon the same button press it is supposed to end the loop which is not happening in the current state.

Seems that i am missing something simple. Any thoughts ?

#define BLYNK_PRINT DebugSerial


int in3 = 7;
int in4 = 8;


#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>
char auth[] = "6787948d586b458a96a1bcf38a952297";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

}

BLYNK_WRITE(V3) //AUTOMATIC
{
  int pinValue2 = param.asInt(); // assigning incoming value from pin V1 to a variable

    {
      do { 
        if (analogRead(0) < 650) 
          {
            digitalWrite(8, HIGH);
            digitalWrite(7, LOW);
          }
          else
          {
            digitalWrite(8, LOW);
            digitalWrite(7, HIGH);
          }
      }
          while (pinValue2 != 0); 
    }        

  }


void loop()
{
  Blynk.run();
}
0 Likes

#2

The do-while loop blocks all other code execution, so further button presses will be ignored until it’s executed.
Depending on how long it takes to execute, it may also starve the Blynk library of processor time, causing disconnections.

The solution is to use V3 to trigger a non-blocking countdown timer.

Pete.

1 Like

#3

How to use non-blocking countdown timer? Please help i will appreciate it

0 Likes

#4

I have various timer examples here for you to learn from…

0 Likes