50 lines
1015 B
C++
50 lines
1015 B
C++
#include <Wire.h>
|
|
#include <SoftwareSerial.h>
|
|
#include "MAX30100_PulseOximeter.h"
|
|
|
|
#define REPORTING_PERIOD_MS 1000
|
|
|
|
SoftwareSerial mySerial(2, 0); // D3 -> TX, D4 -> RX
|
|
|
|
PulseOximeter pox;
|
|
|
|
uint32_t tsLastReport = 0;
|
|
|
|
void onBeatDetected() {
|
|
Serial.println("Beat!");
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
mySerial.begin(9600);
|
|
|
|
if (!pox.begin()) {
|
|
Serial.println("FAILED");
|
|
for(;;);
|
|
} else {
|
|
Serial.println("SUCCESS");
|
|
}
|
|
|
|
pox.setOnBeatDetectedCallback(onBeatDetected);
|
|
}
|
|
|
|
void loop() {
|
|
pox.update();
|
|
|
|
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
|
|
float heartRate = pox.getHeartRate();
|
|
float spO2 = pox.getSpO2();
|
|
|
|
Serial.print("Heart rate:");
|
|
Serial.print(heartRate);
|
|
Serial.print(" bpm / SpO2:");
|
|
Serial.print(spO2);
|
|
Serial.println(" %");
|
|
|
|
String dataToSend = String(heartRate) + "," + String(spO2);
|
|
mySerial.println(dataToSend);
|
|
|
|
tsLastReport = millis();
|
|
}
|
|
}
|