user49411: This is my setup:

Arduino Mega;
HM-10 bluetooth module (bought off ebay, so not sure if genuine but works);
Adafruit Dotstar addressable LED strip;
iOS Blynk app;

Hardware-wise, everything is connected and working properly.
My ultimate goal is to implement this LED strip on my car in the headlights.
At this point though, I want to have everything working off the Blynk app with 3 on/off switch buttons, linked to 3 virtual pins and not consider any code priority for the lights.
I have 3 light "shows" for the strip, which are in their own void functions.
These are: 

Daytime runing lights: DRL(); 
Signal turn indicator: STI();
Police display: POL();

This is my first serious project so consider me a first time coder.
Each switch button should be linked to each light show and turn the strip on and off.
What I want more specifically: when I press the DRL switch, DRL should stay on. Only turn off when switch is pressed again. This works fine.
The STI I want to loop. but when I push the switch, it goes through the function only once. This is what I don't understand, as the Blynk.run() is in the void loop function, and the state of the virtual pin hasn't changed. 
It's the same for the police lights, it goes through the sequence only once, but i want it looped. 
So my question is: How can I loop the STI and POL functions in my code?
I have tried with a while function but i can't get out of it by reading the the virtual pin within the function. 
Here is the entire code:
I am aware that the code might be messy, any input is appreciated.

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <BlynkSimpleSerialBLE.h>

#include <Adafruit_DotStar.h>
#define NUMPIXELS 72

#include <SoftwareSerial.h>

Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

uint32_t amber = 0x020600;
uint32_t white = 0x020202;
uint32_t red = 0x000200;
uint32_t blue = 0x000002;
//SoftwareSerial SerialBLE(10, 11); // RX, TX


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

  if (pinValue1 == 1) {
    Serial.print("Daytime running lights: ON ");
    Serial.println(pinValue1); //showing the actual virtual pin status 0/1
    DRL();
  }
  else {
    Serial.print("Daytime running lights: OFF ");
    Serial.println(pinValue1); //showing the actual virtual pin status 0/1
    OFF();
    Serial.print("off ok"); // this just helps me check where the code has   progressed
  }
}

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

  if (pinValue2 == 1) {
    Serial.print("Dynamic turn indicator: ON ");
    Serial.println(pinValue2);  //showing the actual virtual pin status 0/1
    STI();
  }
  else {
    Serial.print("Dynamic turn indicator: OFF ");
    Serial.println(pinValue2);  //showing the actual virtual pin status 0/1
    OFF();
    Serial.print("off ok"); // this just helps me check where the code has  progressed
  }
}

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

  if (pinValue3 == 1) {
    Serial.print("Police Lights: ON ");
    Serial.println(pinValue3);
    POL();
  }
  else {
    Serial.print("Police Lights: OFF ");
    Serial.println(pinValue3);
    OFF();
    Serial.print("off ok"); // this just helps me check where the code has progressed
  }
}

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Blynk.begin(Serial1, auth);
  Serial.println("Waiting for connections...");

  strip.begin();  //initializes the strip
  strip.show();  //turn off LEDs within NUMPIXELS
}

void OFF() {
  for (int i; i <= 72; i++) { //turn off strip
    strip.setPixelColor(i, 0);
    strip.show();
  }
}

void DRL() {
  for (int i = 0; i <= 72; i++) {
    strip.setPixelColor(i, white);
    strip.show();
    delay(4);
  }
}

void STI() {
  //turn on dinamic indicator
  for (int i = 0; i <= 72; i++) {
    strip.setPixelColor(i, amber);
    strip.show();
    delay(2);
  }

  //turn off dinamic indicator
  for (int i; i <= 72; i++) {
    strip.setPixelColor(i, 0);
  }
  delay (200);  //on condition delay
  strip.show();
  delay (500);  //off condition delay
}

void POL() {

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i <= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(100);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i <= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(100);
}

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


user39409: The way the BLYNK_WRITE functions works is that they are called every time device gets an update of Virtual Pin value from the app. Now if you want to run something on a timer, or in a loop there is a function called BlynkTimer. You write your own function that you want to be looped and use this feature to define how often it should repeat. You can control execution by setting a boolean flag in the BLYNK_WRITE function and checking it in the loop, or by running the enable() and disable() methods of the timer. So, you can do something like this (without libraries, just an example):
BlynkTimer timer; // create timer

void myTimer() 
{
    // toggle an LED
    static bool state;
    digitalWrite(13, state);
    state = !state;
}

void setup()
{
  Blynk.begin(details); // blynk start
  timer.setInterval(1000L, myTimer); // repeat the timer once a second
  pinMode(13, OUTPUT); // LED pin as output
}

void loop()
{
  Blynk.run(); // Runs all Blynk stuff
  timer.run(); // runs BlynkTimer
}

You can read more about it in the docs.

49411: <p>This is my setup:</p>

<ul>
<li>Arduino Mega;</li>
<li>HM-10 bluetooth module (bought off ebay, so not sure if genuine but works);</li>
<li>Adafruit Dotstar addressable LED strip;</li>
<li>iOS Blynk app;</li>
</ul>

<p>Hardware-wise, everything is connected and working properly.</p>

<p>My ultimate goal is to implement this LED strip on my car in the headlights.</p>

<p>At this point though, I want to have everything working off the Blynk app with 3 on/off switch buttons, linked to 3 virtual pins and not consider any code priority for the lights.</p>

<p>I have 3 light "shows" for the strip, which are in their own void functions.</p>

<p>These are: </p>

<ul>
<li>Daytime runing lights: DRL(); </li>
<li>Signal turn indicator: STI();</li>
<li>Police display: POL();</li>
</ul>

<p>This is my first serious project so consider me a first time coder.
Each switch button should be linked to each light show and turn the strip on and off.</p>

<p>What I want more specifically: when I press the DRL switch, DRL should stay on. Only turn off when switch is pressed again. This works fine.</p>

<p>The STI I want to loop. but when I push the switch, it goes through the function only once. This is what I don't understand, as the <code>Blynk.run()</code> is in the void loop function, and the state of the virtual pin hasn't changed. </p>

<p>It's the same for the police lights, it goes through the sequence only once, but i want it looped. </p>

<p>So my question is: How can I loop the STI and POL functions in my code?</p>

<p>I have tried with a while function but i can't get out of it by reading the the virtual pin within the function. </p>

<p>Here is the entire code:</p>

<p>I am aware that the code might be messy, any input is appreciated.
</p>

<pre class="lang-cpp prettyprint-override"><code>#define BLYNK_PRINT Serial
#include &lt;SPI.h&gt;
#include &lt;BlynkSimpleSerialBLE.h&gt;

#include &lt;Adafruit_DotStar.h&gt;
#define NUMPIXELS 72

#include &lt;SoftwareSerial.h&gt;

Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

uint32_t amber = 0x020600;
uint32_t white = 0x020202;
uint32_t red = 0x000200;
uint32_t blue = 0x000002;
//SoftwareSerial SerialBLE(10, 11); // RX, TX


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

  if (pinValue1 == 1) {
    Serial.print("Daytime running lights: ON ");
    Serial.println(pinValue1); //showing the actual virtual pin status 0/1
    DRL();
  }
  else {
    Serial.print("Daytime running lights: OFF ");
    Serial.println(pinValue1); //showing the actual virtual pin status 0/1
    OFF();
    Serial.print("off ok"); // this just helps me check where the code has   progressed
  }
}

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

  if (pinValue2 == 1) {
    Serial.print("Dynamic turn indicator: ON ");
    Serial.println(pinValue2);  //showing the actual virtual pin status 0/1
    STI();
  }
  else {
    Serial.print("Dynamic turn indicator: OFF ");
    Serial.println(pinValue2);  //showing the actual virtual pin status 0/1
    OFF();
    Serial.print("off ok"); // this just helps me check where the code has  progressed
  }
}

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

  if (pinValue3 == 1) {
    Serial.print("Police Lights: ON ");
    Serial.println(pinValue3);
    POL();
  }
  else {
    Serial.print("Police Lights: OFF ");
    Serial.println(pinValue3);
    OFF();
    Serial.print("off ok"); // this just helps me check where the code has progressed
  }
}

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Blynk.begin(Serial1, auth);
  Serial.println("Waiting for connections...");

  strip.begin();  //initializes the strip
  strip.show();  //turn off LEDs within NUMPIXELS
}

void OFF() {
  for (int i; i &lt;= 72; i++) { //turn off strip
    strip.setPixelColor(i, 0);
    strip.show();
  }
}

void DRL() {
  for (int i = 0; i &lt;= 72; i++) {
    strip.setPixelColor(i, white);
    strip.show();
    delay(4);
  }
}

void STI() {
  //turn on dinamic indicator
  for (int i = 0; i &lt;= 72; i++) {
    strip.setPixelColor(i, amber);
    strip.show();
    delay(2);
  }

  //turn off dinamic indicator
  for (int i; i &lt;= 72; i++) {
    strip.setPixelColor(i, 0);
  }
  delay (200);  //on condition delay
  strip.show();
  delay (500);  //off condition delay
}

void POL() {

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, red);
    strip.show();
  }
  delay(30);

  for (int i = 0; i &lt;= 36; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(100);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, blue);
    strip.show();
  }
  delay(30);

  for (int i = 37; i &lt;= 72; i++) {
    strip.setPixelColor(i, 0);
    strip.show();
  }
  delay(100);
}

void loop()
{
  Blynk.run();
}
</code></pre>
 39409: <p>The way the <code>BLYNK_WRITE</code> functions works is that they are called every time device gets an update of Virtual Pin value from the app. Now if you want to run something on a timer, or in a loop there is a function called <code>BlynkTimer</code>. You write your own function that you want to be looped and use this feature to define how often it should repeat. You can control execution by setting a boolean flag in the <code>BLYNK_WRITE</code> function and checking it in the loop, or by running the <code>enable()</code> and <code>disable()</code> methods of the timer. So, you can do something like this (without libraries, just an example):</p>
<pre><code>BlynkTimer timer; // create timer

void myTimer() 
{
    // toggle an LED
    static bool state;
    digitalWrite(13, state);
    state = !state;
}

void setup()
{
  Blynk.begin(details); // blynk start
  timer.setInterval(1000L, myTimer); // repeat the timer once a second
  pinMode(13, OUTPUT); // LED pin as output
}

void loop()
{
  Blynk.run(); // Runs all Blynk stuff
  timer.run(); // runs BlynkTimer
}
</code></pre>
<p>You can read more about it in the <a href="https://docs.blynk.io/en/blynk.edgent-firmware-api/blynk-timer" rel="nofollow noreferrer">docs</a>.</p>
