#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <MAX30100_PulseOximeter.h>
int heartRate = 23.8;
int oxygen = 97.7;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define ONE_WIRE_BUS 4 // DS18B20 on pin 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//MAX30100_PulseOximeter pox;
void scrollText(const char* text) {
int textLength = strlen(text) * 6; // 6 pixels per character in this example
for (int i = -textLength; i < SCREEN_WIDTH; i++) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(i, 20);
display.println(text);
display.display();
delay(50); // Adjust the delay to change the speed of the scrolling
}
}
void takingReadingsAnimation() {
int animationSpeed = 50; // Adjust animation speed if needed
int frames = 4; // Number of frames for the animation
for (int i = 0; i < frames; i++) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Taking readings...");
display.setTextSize(2);
display.setCursor(0, 20);
display.println("Loading");
for (int j = 0; j < i; j++) {
display.print(".");
}
display.display();
delay(animationSpeed);
}
}
void sendingDataAnimation() {
int animationSpeed = 50; // Adjust animation speed if needed
int frames = 4; // Number of frames for the animation
for (int i = 0; i < frames; i++) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Sending data to cloud...");
display.setTextSize(2);
display.setCursor(0, 20);
display.println("Uploading");
for (int j = 0; j < i; j++) {
display.print(".");
}
display.display();
delay(animationSpeed);
}
}
void setup() {
Serial.begin(9600);
// OLED display initialization
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
// MAX30100 sensor initialization
// if (!pox.begin()) {
// Serial.println(F("MAX30100 was not found. Please check wiring/power."));
// while (1);
//}
//pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
//pox.setSampleRate(MAX30100_SAMPLERATE_100HZ);
// DS18B20 sensor initialization
sensors.begin();
}
void loop() {
// Read DS18B20 temperature
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
// Display taking readings animation on OLED
takingReadingsAnimation();
// Display temperature on OLED
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 20);
display.print("Temp: ");
display.print(temperatureC);
display.println(" C");
display.display();
// Read MAX30100 sensor data
// pox.update();
// if (pox.available()) {
// float heartRate = pox.getHeartRate();
// float oxygen = pox.getSpO2();
// Display sending data animation on OLED
sendingDataAnimation();
// Display sensor readings on OLED
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 20);
display.print("HR: ");
display.print(heartRate);
display.println(" bpm");
display.setCursor(0, 40);
display.print("SPO2: ");
display.print(oxygen);
display.println("%");
display.display();
// Here, you would integrate the code to send data to your cloud service/platform
// Replace this with your actual cloud communication code
// Delay before taking the next set of readings
delay(5000);
// }
}