Hi everybody! please help!
i try to use INA and esp8266 to measure voltage and current values, control max current or max voltage. When I turn on or off the CVmode switch, change the slide value, nothing changes, it always shows cvmode=1, Slide value=0. Why???
• ESP8266 with INA219
• Blynk APP on Smartphone OS (iOS 3.5.4 and Android 1.9.1(122))
• Blynk Library version 1.2.0
• My sketch code is like that.
You provided a screenshot of your mobile dashboard, but when I asked for details of how you’ve configured these widgets you’ve provided a screenshot of the web dashboard widgets.
You have cvmode defined as a global variable of type Integer at the top of your code…
but you are then declaring a local integer variable with the same name inside your BLYNK_WRITE(V7) callback…
This means that the local version of cvmode isn’t visible outside of BLYNK_WRITE(V7).
To fix that, change your BLYNK_WRITE(V7) to this…
BLYNK_WRITE(V7)
{
cvmode = param.asInt(); // <<< `int` removed from beginning
Serial.print("V7 cvmode value is: ");
Serial.println(cvmode);
}
You also need to do the same thing with setpercent which you are re-declaring as local within BLYNK_WRITE(V8)
2 - Difference between “=” and "=="
In void ina219values() you have this…
The problem is that if (cvmode = 0) should be if (cvmode == 0)
and if (cvmode = 1) should be if (cvmode == 1)
When you use cvmode = 0 it means “set cvmode to 0”, so cvmode is being set to 0, then in the next piece of code it’s being set to 1 - which is why cvmode is always 1 in your serial monitor.
Double equals signs ("==") means “compare the two values” so if(cvmode==0) means "compare the current value of cvmode and 0, if they are the same then the if statement evaluates as true"