我找到了一个代码,但我不太理解BPM = ( 1.0 / PulseInterval) * 60.0 *1000的公式;60.0应该是1分钟(每分钟的节拍),但为什么是1.0/ PulseInterval)和*1000?
int UpperThreshold = 518;
int LowerThreshold = 490;
int reading = 0;
float BPM = 0.0;
bool IgnoreReading = false;
bool FirstPulseDetected = false;
unsigned long FirstPulseTime = 0;
unsigned long SecondPulseTime = 0;
unsigned long PulseInterval = 0;
const unsigned long delayTime = 10;
const unsigned long delayTime2 = 1000;
const unsigned long baudRate = 9600;
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
int Signal;
void bpm() {
reading = Signal;
// Heart beat leading edge detected.
if (reading > UpperThreshold && IgnoreReading == false) {
if (FirstPulseDetected == false) {
FirstPulseTime = millis();
FirstPulseDetected = true;
} else {
SecondPulseTime = millis();
PulseInterval = SecondPulseTime - FirstPulseTime;
FirstPulseTime = SecondPulseTime;
}
IgnoreReading = true;
if (reading < LowerThreshold && IgnoreReading == true) {
IgnoreReading = false;
noTone(pinSPEAKER);
digitalWrite(blinkPin, LOW);
}
// Calculate Beats Per Minute.
BPM = (1.0 / PulseInterval) * 60.0 * 1000;
}发布于 2019-07-06 18:12:44
脉冲间隔以毫秒为单位。除以1000得到秒。你想要的不是每秒的节拍,而是每分钟的节拍。现在还有60秒。除以60x1000可以将毫秒更改为分钟。
脉冲间隔的另一个名称是脉冲周期。
周期的倒数是频率。
看起来像millis()将时钟值转换为毫秒。
https://stackoverflow.com/questions/56913033
复制相似问题