简体   繁体   English

如何获得beaglebone黑色LED的闪烁频率?

[英]How to get frequency of blinking of LED in beaglebone black ?

I have the following code which is used to blink USR3 LED of beaglebone black. 我有以下代码,用于使beaglebone黑色的USR3 LED闪烁。

var b = require('bonescript');
var led = "USR3";
var state = 0;

b.pinMode(led, 'out');
toggleLED = function() {
    state = state ? 0 : 1;
    b.digitalWrite(led, state);
};

timer = setInterval(toggleLED, 200); //doubling the time to toggle led half as fast

stopTimer = function() {
    clearInterval(timer);
};

setTimeout(stopTimer, 3000);

The time set while calling setTimeout is in milliseconds. 调用setTimeout时设置的时间以毫秒为单位。 So the code works and blinks the led for a certain number of times in 3 seconds (ie 3000 milliseconds.) Is there a way to output this frequency ? 因此,代码可以正常工作,并在3秒钟内(即3000毫秒)使LED闪烁一定次数。是否可以输出该频率?

You are defining the frequency by letting the LED toggle ever 200ms. 您要通过使LED切换200ms来定义频率。 Frequency is defined as 1/period of a full phase of the signal. 频率定义为信号全相位的1 /周期。 For a rectangle signal with 0 / 1: ,,,, |''''|,,,,| 对于具有0/1的矩形信号,、、、、 |''''| 、、、、 | ''''|,,,, your period is 200ms + 200ms because you toggle every 200ms. ''''| ,,,您的周期为200ms + 200ms,因为您每200ms进行一次切换。 Then the frequency is calculated as 1/400ms => 2,5Hz 然后计算出频率为1 / 400ms => 2,5Hz

If this isn't what your looking for, please refine your question. 如果这不是您要找的内容,请完善您的问题。

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

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