Repeating a piece of code till interrupted

Hi Guys,

I am new to Blynk and i have managed to control various things using app as well sending URL using IFTTT.

However, im a little confused on how to implement 1 of the applications i have been working on.

Basically, i have added a button in my app, that needs to do a specific function. I have assigned that button to a pin V7. So when i switch the button on, V7 becomes 1 and the function should be executed.When V7=0, the function should stop executing and wait for next input. The function goes like this:

BLYNK_WRITE(V7) //Button Widget is writing to pin V7----
{

int pinData = param.asInt();

if(pinData)
{
Statement 1;
Statement 2;
}

else
off();
}

Now the Problem is, when V7 becomes 1, after checking its value, the function gets repeated once but then it stops(Im actually dimming a LED). So basically my LED dims once and stops. So how do i get it to repeat continuously till i switch off my button?

Any help with this concept would be appreciated, thanks

@Aviral_Malay You’ve to be specific what the function is. It should not be a blocking function. The best way to implement this is to run that task on a timer. Let us call the function abc.

int timerID

BLYNK_WRITE(V7)
{
int pinData = param.asint();
 if (pinData)
  {
    timerID = timer.setInterval(1000L, abc);
  }
 else
  {
    timer.delete(timerID);
  }
}

void abc()
{
Statement 1;
Statement 2;
}

Change the time interval as desired in the setInterval statement.