我正在执行我的第一个IOT
项目hello world
闪烁,我试图开始使用物联网书,但遇到了问题。
这本书是这样的:https://webofthings.org/2016/10/23/node-gpio-and-the-raspberry-pi/。
但是当我尝试运行代码时,我得到了错误。
/home/pi/Desktop/hello_world/node_modules/onoff/onoff.js:9 const HIGH_BUF = Buffer.from('1');
TypeError: this is not a typed array.
at Function.from (native)
at Object.<anonymous>
(/home/pi/Desktop/faizan/node_modules/onoff/onoff.js:9:25)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/pi/Desktop/faizan/app.js:1:75)
at Module._compile (module.js:409:26)
我正在运行的代码是
var onoff = require('onoff');
var Gpio = onoff.Gpio,
led = new Gpio(4,'out'),
interval;
interval = setInterval(function (){
var value = (led.readSync() + 1) % 2;
led.write(value, function() {
console.log("Changed LED state to: " + value);
});
}, 2000);
process.on('SIGINT', function () {
clearInterval(interval);
led.writeSync(0);
led.unexport();
console.log('Bye, bye!');
process.exit();
});