forked from manjuhm/PulseOximeter_LCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPulseOximeter_LCD.ino
65 lines (45 loc) · 1.3 KB
/
PulseOximeter_LCD.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "MAX30100_PulseOximeter.h"
LiquidCrystal_I2C lcd(0x27,16,2); //0x27 is the i2c address, while 16 = columns, and 2 = rows.
#define REPORTING_PERIOD_MS 1000
PulseOximeter pox;
uint32_t tsLastReport = 0;
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
lcd.init(); //Initialize the LCD
lcd.backlight(); //Activate the backlight
lcd.home();
// 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()
{
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
// Display on LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("BPM: ");
lcd.print(pox.getHeartRate());
lcd.setCursor(0,1);
lcd.print("SpO2: ");
lcd.print(pox.getSpO2());
lcd.print("%");
tsLastReport = millis();
}
}