RGB LED闪烁着Arduino + Johnny-five

时间:2017-01-20 21:55:36

标签: javascript arduino johnny-five

我有这个RGB 5050 LED之旅。我目前正在使用Arduino板和Johnny-Five平台,因为我需要使用Javascript来控制它。 我想让LED在某个频率上闪烁,这会慢慢增加。

对于单色LED,他们有这个命令:

led.fade(brightness, ms)

但这对RGB LED不起作用(这只是愚蠢的)。

我发现的唯一选择是:

function FadeIN(){
  led.intensity(i);
  i++; 

  if(i < 100){
    setTimeout( FadeIN, (Timer[y]/20));
  }                        
}

这是一个循环函数,我必须这样做,因为你实际上不能在setTimeout()for循环中使用while。我也使用类似的功能来淡出LED。

问题是:它的工作时间很短。但有时候它会轻轻地跳过一声哔哔声。此外,有时它只是如此之快以至于光度降低(淡出)几乎可以忽略不计,甚至达不到&#34; 0&#34;并开始再次增加。

我确定这不是硬件限制(Arduino),因为我已经使用Arduino Editor和C ++实现了我想要的功能。

在J5网站上,他们有很多命令和示例仅适用于单色LED,但没有RGB。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

请注意,RGB LED需要以与单色LED不同的方式进行实例化。毕竟,他们有更多的针脚!这是一个例子:

var led = new five.Led.RGB([9, 10, 11]);

https://github.com/rwaldron/johnny-five/wiki/led.rgbhttp://johnny-five.io/api/led.rgb/使用RGB LED的文档。实际上,这里有关于随时间改变RGB LED强度的文档:http://johnny-five.io/examples/led-rgb-intensity/。从该文件:

var temporal = require("temporal");
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {

  // Initialize the RGB LED
  var led = new five.Led.RGB([6, 5, 3]);

  // Set to full intensity red
  console.log("100% red");
  led.color("#FF0000");

  temporal.queue([{
    // After 3 seconds, dim to 30% intensity
    wait: 3000,
    task: function() {
      console.log("30% red");
      led.intensity(30);
    }
  }, {
    // 3 secs then turn blue, still 30% intensity
    wait: 3000,
    task: function() {
      console.log("30% blue");
      led.color("#0000FF");
    }
  }, {
    // Another 3 seconds, go full intensity blue
    wait: 3000,
    task: function() {
      console.log("100% blue");
      led.intensity(100);
    }
  }, ]);
});