我找到了一个代码,但是我不太了解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;
}
答案 0 :(得分:0)
脉冲间隔以毫秒为单位。 除以1000得到秒。 您不希望每秒跳动,而是每分钟跳动。 一分钟有60秒。 除以60x1000,从毫秒变为分钟。
脉冲间隔的另一个名称是脉冲周期。
周期的倒数就是频率。
好像millis()将时钟值转换为毫秒。