Created
May 21, 2018 16:17
-
-
Save arduinothai/45a7baf8771bc6b561a903cd00fd86ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include "MAX30100_PulseOximeter.h" | |
#define REPORTING_PERIOD_MS 1000 | |
PulseOximeter pox; | |
uint32_t tsLastReport = 0; | |
// Callback (registered below) fired when a pulse is detected | |
void onBeatDetected() | |
{ | |
Serial.println("Beat!"); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.print("Initializing pulse oximeter.."); | |
if (!pox.begin()) { | |
Serial.println("FAILED"); | |
for(;;); | |
} else { | |
Serial.println("SUCCESS"); | |
} | |
pox.setOnBeatDetectedCallback(onBeatDetected); | |
} | |
void loop() | |
{ | |
pox.update(); | |
if (millis() - tsLastReport > REPORTING_PERIOD_MS) { | |
Serial.print("Heart rate:"); | |
Serial.print(pox.getHeartRate()); | |
Serial.print("bpm / SpO2:"); | |
Serial.print(pox.getSpO2()); | |
Serial.println("%"); | |
tsLastReport = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment