[英]Delay led in Johnny-five
How do I a loop in javascript with API johnny-five/arduino
. 如何使用API
johnny-five/arduino
在JavaScript中循环。 This looping is to delay on/off
to my led. 这种循环是为了延迟
on/off
我的LED。 Example: 例:
while(true){
while(time<1500){
'led off'
}
while(time<1500){
'led on'
}
}
My actual code is bellow. 我的实际代码如下。 I remove the header
http and others
and the listen
in the end. 我删除标题
http and others
,最后删除listen
。
arduino or board on: arduino或登上:
arduino.on('ready', function(){
console.log("Arduino Pronto");
led0 = new five.Led(13);
led1 = new five.Led(12);
led2 = new five.Led(11);
this.digitalRead(10, function(value) {
console.log(value);
});
});
Server function: 服务器功能:
function servidor(req, res){
var url = req.url;
if(url == '/'){
res.writeHead(200);
res.end(fs.readFileSync('view/index.html'));
}else if(url == '/led0'){
res.writeHead(302, {'Location': '/'});
res.end();
led0.toggle();
}else if(url == '/led1'){
res.writeHead(302, {'Location': '/'});
res.end();
led1.toggle();
}else if(url == '/led2'){
res.writeHead(302, {'Location': '/'});
res.end();
led2.toggle();
}else{
res.writeHead(200);
res.end("<h1>Erro 404</h1>");
}
};
Its possible? 这是可能的?
You can delay your LEDs using setTimeout
for a single delay or setInterval
for a repeated delay: 您可以使用
setTimeout
延迟单个延迟,或者使用setInterval
延迟重复延迟来延迟LED:
setInterval(() => {
led.toggle();
}, 1500);
This is an asynchronous delay. 这是一个异步延迟。 If you need a synchronous delay, you could use the sleep package or use
execSync
from the Node child_process module: execSync("sleep 1.5")
. 如果你需要一个同步延迟,您可以使用睡眠包或使用
execSync
从节点child_process模块: execSync("sleep 1.5")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.