Detecting Multiple clicks on Virtual Pin/Button

I am trying to implement a button widget that can detect multiple clicks rather than a long hold and release and then get a particle photon to act upon that.

I’ve spent the evening searching the forum and haven’t been able to come up with a solution. I’ve seen a few examples on here of a long hold using timers and will use that approach if I can’t achieve my first goal.

Can anyone point me in the right direction please.

Add a counter to count the number of clicks and act on that.

Dirty code:

int counter = 0;

BLYNK_WRITE(V0)
{
 if(param.asInt())
 {
  counter++;
 }

 if(counter == 10)
 {
 // do stuff here
 counter = 0; // and reset counter of course!
 }
}

Bingo, and so obvious. should of gone to bed hours ago. Many thanks.

I might be off on some syntax, if you want to collect the amount of presses and have code act upon it
I would do something like this.

This will be a bit stressful perhaps so adjust your fireDelay down here :stuck_out_tongue:

int presses = 0;			// tracks presses
int fireDelay = 1;			// execute after 1 second from first presses
boolean fireEvent = false;	// check flag
SimpleTimer timer;		// timer for firing event

BLYNK_WRITE(V0)
{
	presses++;
	
	// Check flag is to prevent multiple fires	
	if (!fireEvent) 
	{
		fireEvent = true;
		timer.setTimeout(fireDelay * 1000L, doFunction());
	}
	
}

void doFunction()
{
	//doStuffHere
	//use 'presses' variable for number of presses
	
	presses = 0;
	fireEvent = false;	
}
1 Like