我的电路板设置有两个按钮(带上拉电阻)和两个 LED。我希望每个按钮打开相应的 LED 并关闭另一个。
代码:
var five = require('johnny-five');
var board = new five.Board({ port: "COM3" });
board.on("ready", function() {
// def led
ledGreen = new five.Pin(13);
ledYellow = new five.Pin(7);
buttonRight = new five.Button({
pin: 2,
inverted:true
});
buttonLeft = new five.Button({
pin: 3,
inverted:true
});
buttonRight.on("hit", function(value) {
ledGreen.high();
ledYellow.low();
console.log("Button Right - Green ");
});
buttonLeft.on("hit", function(value) {
ledGreen.low();
ledYellow.high();
console.log("Button Left - Yellow");
});
});
控制台显示正确的推送状态,但有时对应的 LED 不亮,而另一个熄灭。它真的是零星的。我错过了什么?这只发生在 NW.js 环境中,独立节点应用程序运行良好。我有 nwjs-j5-fix。