3 ms·
With JavaScript (nodejs) var lightsOn = true; setInterval(blink, 2000); function blink() { var fs = require("fs"); fs.writeFile("/sys/class/l
by z3t4 11y ago
With JavaScript (nodejs)
var lightsOn = true;
setInterval(blink, 2000);
function blink() {
var fs = require("fs");
fs.writeFile("/sys/class/leds/beaglebone:green:usr0/brightness", lightsOn, function (err) {
if (err) throw err;
});
lightsOn = lightsOn ? false : true;
}
- have_faith 11y agoIt makes no difference but for some reason I feel the urge to shorten the last line to: lightsOn = !lightsOn; I'll see myself out.
- polishninja 11y agoDon't forget to turn off the light on your way out. lightsOn = !lightsOn || lightsOn
- Cshelton 11y agoEvery time I write that in JavaScript, I delete it and just use ! As well haha
- mcconnma 11y agoWriting a boolean type to SysFS/GPIO from NodeJS doesn't quite work so I tweaked your example to following similar pattern of the other languages. Thanks.
- z3t4 11y agoI wanted to show the power of JavaScript types, and you got a type bug? What the irony. I'll probably report that as a bug in nodejs or an undocumented "feature".