Änderungen

KY-039 Herzschlag Sensor Modul

389 Byte entfernt, 15:05, 1. Apr. 2016
/* Codebeispiel Arduino */
==Codebeispiel Arduino==
Das folgende Code-Beispiel stammt aus der Feder von Dan Truong, welcher diesen Code unter [[Https://forum.arduino.cc/index.php?topic=209140.msg2168654|folgenden Link]] veröffentlicht hat. Dieser steht unter der MIT OpenSource Lizenz zur Verfügung. Die unten stehende Version ist die übersetzte deutsche Fassung - das original steht unten zum Download zur Verfügung.
 <pre class="brush:cpp">////////////////////////////////////////////////////////////////////////
/// Copyright (c)2015 Dan Truong
/// Permission is granted to use this software under the MIT
///
/// KY039 Arduino Heartrate Monitor V1.0 (April 02, 2015)
////////////////////////////////////////////////////////////////////////<br /><br />// German Comments by Joy-IT
////////////////////////////////////////////////////////////////////////
/// or too fast, it causes glitches and false beat detection.
////////////////////////////////////////////////////////////////////////
#define HBDEBUG(i) i//#define HBDEBUG(i)
int rawValue;
static int maxValue = 0;
static bool isPeak = false;
HBDEBUG(Serial.print(maxValue); Serial.print("xp, "));
bool result = false;
// Separated because analogRead() may not return an int
rawValue *= (1000/delay);
HBDEBUG(Serial.print(isPeak); Serial.print("p, ")); HBDEBUG(Serial.print(rawValue); Serial.print("r, ")); HBDEBUG(Serial.print(maxValue); Serial.print("m, "));
// If sensor shifts, then max is out of whack.
// Just reset max to a new baseline.
if (rawValue * 4L < maxValue) { <br /> maxValue = rawValue * 0.8; HBDEBUG(Serial.print("RESET, ")); <br /> rawValue = rawValue *4L; HBDEBUG(Serial.print(rawValue); Serial.print("rw, "));
}
if (isPeak == false) {
result = true;
HBDEBUG(Serial.print(result); Serial.print(", *")); }
isPeak = true;
} else if (rawValue < maxValue - (3000/delay)) {
maxValue-=(1000/delay);
}
HBDEBUG(Serial.print("\n"));
return result;
}
Bürokrat, Administrator
611
Bearbeitungen