Some times you need code that is dependent on parameter. Like having one up to five analog reads depense on your device. Having it readable eats up lots of space.
Is there a way to minify Sting module?
count = 3;
name = 'analogRead';
var APINS = [ D28, D3, D4, D30, D29 ];
var analogRead = {};
var buildModule = (c) =>{
var module = "", i = 0;
module = `exports = function (interval) {
var a0 = 0
, a1 = 0
, a2 = 0
, a3 = 0
, a4 = 0
;
setInterval(() => {
`;
for (i = 0; i < count; i++) {
module += ' a'+i+' = analogRead('+APINS[i]+');\n';
}
module +=` print(`;
module += ' a'+0+'.toFixed(3)\n';
for (i =1; i < count; i++) {
module += ' , a'+i+'.toFixed(3)\n';
}
module +=` );
}, interval);
}`;
require('Storage').write(name, module);
print(module);
};
buildModule(count);
analogRead = require(name);
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.
Some times you need code that is dependent on parameter. Like having one up to five analog reads depense on your device. Having it readable eats up lots of space.
Is there a way to minify Sting module?
output