#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
Wire.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
int heartRate = simulateMAX30102();
float oxygenSaturation = readOxygenSaturation();
displayInfo(heartRate, oxygenSaturation);
delay(1000);
}
int simulateMAX30102() {
return random(60, 100);
}
float readOxygenSaturation() {
return random(95, 100);
}
void displayInfo(int heartRate, float oxygenSaturation) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(F("Heart Rate: "));
display.println(heartRate);
display.println(F("bpm"));
display.println(F("Oxygen Saturation: "));
display.print(oxygenSaturation, 2);
display.println(F("%"));
display.display();
}Loading
ssd1306
ssd1306