我的电路板设置有两个按钮(带上拉电阻)和两个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环境中,独立节点app运行正常。我有nwjs-j5-fix。
答案 0 :(得分:0)
您可以尝试初始化引脚......
ledGreen = new five.Pin(13);
ledYellow = new five.Pin(7);
ledGreen.low();
ledYellow.low();
这将确保他们关闭。