from machine import Pin, ADC, I2C
import ssd1306
import time
# Initialize I2C for OLED display (SCL=22, SDA=21)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
display = ssd1306.SSD1306_I2C(128, 64, i2c)
# Initialize ADC for potentiometer on GPIO 34
pot = ADC(Pin(34))
pot.atten(ADC.ATTN_11DB) # Full voltage range (0 - 3.3V)
while True:
# Read potentiometer value (0 to 4095)
pot_value = pot.read()
# Map the potentiometer to health metrics
heart_rate = int(65 + (pot_value / 4095) * 75) # 65 to 140 BPM
temperature = int(36 + (pot_value / 4095) * 4) # 36 to 40 °C
spo2 = int(99 - (pot_value / 4095) * 11) # 99% down to 88%
# Clear screen
display.fill(0)
# Header
display.text("HEALTH MONITOR", 12, 2)
display.hline(0, 12, 128, 1)
# Display metrics
display.text(f"Heart Rate: {heart_rate}", 0, 18)
display.text(f"Temp: {temperature} C", 0, 30)
display.text(f"SpO2: {spo2} %", 0, 42)
# Trigger warning if values cross normal safety thresholds
if heart_rate > 100 or temperature > 37 or spo2 < 95:
display.text("! ABNORMAL !", 16, 54)
display.show()
time.sleep(0.2)Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306