'command in if else loop repeat when I release button
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
