簡體   English   中英

RGB LED閃爍着Arduino + Johnny-five

[英]RGB LED blinking with 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));
  }                        
}

這是一個循環函數,我必須這樣做,因為你實際上不能在forwhile循環中使用setTimeout() 我也使用類似的功能淡出LED。

問題是:它的工作時間很短。 但有時候它會輕輕地跳過一聲嗶嗶聲。 此外,有時它只是如此之快以至於光度降低(淡出)幾乎可以忽略不計,甚至達不到“0”並再次開始增加。

我確定這不是硬件限制(Arduino),因為我使用Arduino Editor和C ++實現了我想要的功能。

在J5網站上,他們有很多命令和示例僅適用於單色LED,但沒有RGB。

有人可以幫忙嗎?

請注意,RGB LED需要以與單色LED不同的方式實例化。 畢竟,他們有更多的針腳! 這是一個例子:

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

有關使用RGB LED的文檔,請訪問https://github.com/rwaldron/johnny-five/wiki/led.rgbhttp://johnny-five.io/api/led.rgb/ 事實上,這里有關於隨時間改變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);
    }
  }, ]);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM