From aa6cb2eef6ec938801d7924f79576715d33275cc Mon Sep 17 00:00:00 2001 From: thrivenichintha <58471724+thrivenichintha@users.noreply.github.com> Date: Sat, 23 Oct 2021 11:33:29 +0530 Subject: [PATCH] Create max30100 --- max30100 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 max30100 diff --git a/max30100 b/max30100 new file mode 100644 index 0000000..4e9034c --- /dev/null +++ b/max30100 @@ -0,0 +1,47 @@ +#include +#include "MAX30100_PulseOximeter.h" + +#define REPORTING_PERIOD_MS 1000 + +PulseOximeter pox; +uint32_t tsLastReport = 0; + +void onBeatDetected() +{ + Serial.println("Beat!"); +} + +void setup() +{ + Serial.begin(115200); + Serial.print("Initializing pulse oximeter.."); + + // Initialize the PulseOximeter instance + // Failures are generally due to an improper I2C wiring, missing power supply + // or wrong target chip + if (!pox.begin()) { + Serial.println("FAILED"); + for(;;); + } else { + Serial.println("SUCCESS"); + } + pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); + + // Register a callback for the beat detection + pox.setOnBeatDetectedCallback(onBeatDetected); +} + +void loop() +{ + // Make sure to call update as fast as possible + 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(); + } +}