0

In blynk I create a virtual pin v4 and v5 and the minimum and maximum value of both is 0 and 1, In dashboard I have two push button,the first one link to v4 and the second one link to v5, and I use this code

int n;

BLYNK_WRITE(V4) 
{   
    int hit = param.asInt();   
    if (hit = 1)
    {
       n -= 1;
       Blynk.virtualWrite(V2,n);
       Serial.println(param.asInt());
    } 
} 
BLYNK_WRITE(V5) 
{   
    int hit = param.asInt();   
    if (hit = 1)
    {
       n += 1;
       Blynk.virtualWrite(V2,n);
       Serial.println(param.asInt());
    } 
}

when I press the first button(v4) hit become 1, n increase by 1 and serial print n, and when I release the button, hit become 0 but n still increase by 1 and serial print n instead of nothing happen, it also happen the same when I press and release the second button(v5). I don't know why, when hit become 0 but code in if loop still running. I what it to running only one time when I press the button.

bqhon
  • 1
  • 1
    `hit = 1` should be `hit == 1`. Make sure your compiler warnings are turned on – Alan Birtles Mar 07 '22 at 09:34
  • thank you very much, it's working now, before this I check how to use if else but didn't notice that I need to use "==" – bqhon Mar 07 '22 at 10:29
  • Using `=` makes it an assignment. It sets hit to 1 then checks if the value is non zero. if so the condition for the if is true. – drescherjm Mar 07 '22 at 12:40

0 Answers0