#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int pulsePin = A0; // Connect the potentiometer's middle pin to A0
void setup() {
Serial.begin(9600);
pinMode(pulsePin, INPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize the OLED display
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
}
void loop() {
int pulseValue = analogRead(pulsePin);
int heartRate = map(pulseValue, 0, 1023, 40, 200); // Map the potentiometer values to a range of possible heart rates
display.clearDisplay();
display.setCursor(0, 0);
display.print("Heart Rate: ");
display.print(heartRate);
display.println(" BPM");
display.display();
delay(200);
}