简体   繁体   English

RGB LED闪烁着Arduino + Johnny-five

[英]RGB LED blinking with Arduino + Johnny-five

I have this RGB 5050 LED trip. 我有这个RGB 5050 LED之旅。 Im currently using this with an Arduino board and Johnny-Five platform because I need to use Javascript to control it. 我目前正在使用Arduino板和Johnny-Five平台,因为我需要使用Javascript来控制它。 I want to make the LED blink on a certain frequency and this will increase slowly. 我想让LED在某个频率上闪烁,这会慢慢增加。

For a single color LED, they have this command: 对于单色LED,他们有这个命令:

led.fade(brightness, ms)

but this doesn't work for RGB LED (what is just stupid). 但这对RGB LED不起作用(这只是愚蠢的)。

The only option that I've found is this: 我发现的唯一选择是:

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

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

This is a loop function, I had to do in this way because you actually can't use setTimeout() inside a for or while loop. 这是一个循环函数,我必须这样做,因为你实际上不能在forwhile循环中使用setTimeout() Im also using a similar function to Fade Out the LED. 我也使用类似的功能淡出LED。

The issue is: It works for a short period. 问题是:它的工作时间很短。 But sometimes it literally skips a beep. 但有时候它会轻轻地跳过一声哔哔声。 Also, sometimes it just is so fast that the luminosity reduction (Fade Out) is just negligible, not even reaching "0" and starting to increase again. 此外,有时它只是如此之快以至于光度降低(淡出)几乎可以忽略不计,甚至达不到“0”并再次开始增加。

Im sure that this isn't a hardware limitation (Arduino), because I've achieve what I want using Arduino Editor and C++. 我确定这不是硬件限制(Arduino),因为我使用Arduino Editor和C ++实现了我想要的功能。

At J5 website they have a lot of commands and examples only for single color LED, but nothing for RGB. 在J5网站上,他们有很多命令和示例仅适用于单色LED,但没有RGB。

Can anyone help? 有人可以帮忙吗?

Note that the RGB LEDs need to be instantiated differently than the single color LEDs. 请注意,RGB LED需要以与单色LED不同的方式实例化。 They have more pins, after all! 毕竟,他们有更多的针脚! Here's an example: 这是一个例子:

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

There is documentation for using RGB LEDs at https://github.com/rwaldron/johnny-five/wiki/led.rgb and http://johnny-five.io/api/led.rgb/ . 有关使用RGB LED的文档,请访问https://github.com/rwaldron/johnny-five/wiki/led.rgbhttp://johnny-five.io/api/led.rgb/ In fact, here is documentation on changing the RGB LEDs's intensity over time: http://johnny-five.io/examples/led-rgb-intensity/ . 事实上,这里有关于随时间改变RGB LED强度的文档: http//johnny-five.io/examples/led-rgb-intensity/ From that document: 从该文件:

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);
    }
  }, ]);
});

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

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