简体   繁体   English

在NW.js中以Johnny-Five 5和Arduino为首的打开/关闭

[英]Turning on/off led with johnny-five and arduino in NW.js

I have my board setup with two buttons (with pull-up resistors) and two LEDs. 我的板卡设置有两个按钮(带有上拉电阻)和两个LED。 I want each button to turn on corresponding LED and turn the other off. 我希望每个按钮打开相应的LED,然后关闭另一个。

Code: 码:

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");
  });

});

Console shows correct push states, but sometimes corresponding LED wont turn on, and other one turn off. 控制台显示正确的推动状态,但有时相应的LED不会点亮,而其他LED会熄灭。 Its really sporadic. 它确实是零星的。 What did I miss? 我错过了什么? This occurrs only in NW.js evironment, standalone node app runs fine. 仅在NW.js环境中发生这种情况,独立节点应用程序运行良好。 I have nwjs-j5-fix. 我有nwjs-j5-fix。

You can try initialize the pins... 您可以尝试初始化引脚...

ledGreen = new five.Pin(13);
ledYellow = new five.Pin(7);

ledGreen.low();
ledYellow.low();

this will ensure they are off. 这将确保它们关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM