我有这个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));
}
}这是一个循环函数,我必须这样做,因为你实际上不能在for或while循环中使用setTimeout()。我也在使用类似的功能来淡出LED。
问题是:它在短时间内有效。但有时它确实会跳过一声嘟嘟声。此外,有时它只是太快了,亮度降低(淡出)可以忽略不计,甚至没有达到"0“,并开始再次增加。
我确信这不是硬件限制( Arduino ),因为我已经使用Arduino编辑器和C++实现了我想要的。
在J5网站上,他们有很多命令和示例,只针对单色发光二极管,而没有针对RGB的。
有人能帮上忙吗?
发布于 2017-02-15 05:34:20
请注意,RGB LED需要以不同于单色LED的方式实例化。毕竟,他们有更多的引脚!下面是一个例子:
var led = new five.Led.RGB([9, 10, 11]);在https://github.com/rwaldron/johnny-five/wiki/led.rgb和http://johnny-five.io/api/led.rgb/上有使用RGB的文档。事实上,以下是随时间改变RGB强度的文档: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);
}
}, ]);
});https://stackoverflow.com/questions/41772977
复制相似问题