var high = 0.55;
var low = 0.0017;
function map_value(val, in_min, in_max, out_min, out_max){
var result = (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
if(result < out_min) {
return out_min;
}
else if(result > out_max) {
return out_max;
}
return result;
}
function onTimer() {
var h = analogRead(A0);
var hp = map_value(h, low, high, 0, 100);
var percentage = hp.toFixed(0)+"%";
// Clear display
g.clear();
// Use the small font for a title
g.setFontBitmap();
g.drawString("Soil moister:");
// Use a large font for the value itself
g.setFontVector(10);
g.drawString(percentage, 5,10);
// Update the screen
g.flip();
}
// Update soil moister every 2 seconds
setInterval(onTimer, 2000);
// Update soil moister immediately
onTimer();
Feedback on the code is welcome
I have 3 pucks im gooing to try next :) Im gooing to send via bluetooth to my pixl.js
edit:
Strange the high and low changes with battery vs plug
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I came up with this
Feedback on the code is welcome
I have 3 pucks im gooing to try next :) Im gooing to send via bluetooth to my pixl.js
edit:
Strange the high and low changes with battery vs plug