BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Float value range in level widget?


#1

i’m using the level widget to display battery charge status. My battery is fully charged at around 12.4v and is depleted at around 10.7v. Unfortunately the widget only lets me use a range between non decimal values. Any way to use decimals in the widget?


#2

Float values are supported only on virtual pins, you can change the pin of your level widget and change your sketch to send decimals to it’s virtual pin and it will show them.


#3

just multiple the battery V by 10 and use that in your level so:
min 107 max 124


#4

Thank you wolph42, your idea worked. I just had to add “Math.round” to get rid of the resulting float value which was causing the level to constantly react to subtle changes in voltage.

setInterval(function() {
var voltage = spawn('python',["voltage.py"]);
voltage.stdout.on('data',(function(volt){ // executes child process
var volt = volt.toString('utf8') // assigns load as a string to variable
blynk.virtualWrite(11, volt) // writes to Blynk label
var level = Math.round(volt * 10);
blynk.virtualWrite(3, level)
}))}, 1000);