How can I include BLYNK_WRITE(V7) in the timer function?

Hello everyone,

I am trying to implement BLYNK_WRITE(V7) using the timer function. If I create an function, let’s say, void checkPin () , and include BLYNK_WRITE(V7) in the void checkPin function, is does not work. any idea any help will be appreciated.

BLYNK_WRITE(V7) 
{
  if (param.asInt() == 0) 
  {   
  digitalWrite(1, LOW); 
  } 
  else 
  {
  digitalWrite(1, HIGH);
  }
}

You don’t need to check virtual pins, the function is automatically called when you use the corresponding widget (just check you set virtual pin number correctly).

It seems to be a common mistake that people treat BLYNK_WRITE as a function CALL. Rather, it is a function DECLARATION. Blynk.virtualWrite is a function call, but they are different.

I think of it this way:

Blynk functions in ALL CAPS are using the app dashboard context. E.g. in BLYNK_WRITE() the dashboard is writing to your sketch so you declare this function to define how to capture the value it is sending.

Blynk functions in mixed case are the reverse: your sketch is writing to the app dashboard. So with Blynbk.virtualWrite() you are sending the dashboard a value from your sketch.

I found this a little confusing at first, but thinking of it this way helped me.

RD7

4 Likes