Professional Documents
Culture Documents
Bahasa Pemrograman
Bahasa Pemrograman
Bahasa Pemrograman
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include "MAX30105.h"
#include "heartRate.h"
MAX30105 particleSensor;
float beatsPerMinute;
int beatAvg;
int count;
int perCent;
int avgIr;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C
addr 0x3D (for the 128x64)
pinMode(buttonPin, INPUT_PULLUP);
// Initialize sensor
particleSensor.begin(Wire, I2C_SPEED_FAST); //Use default I2C port,
400kHz speed
particleSensor.setup(); //Configure sensor with default settings
particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to
indicate sensor is running
particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
}
}
void buttonChange()
{
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if (buttonState == HIGH) {
ledState = !ledState; // HIGH to LOW
tone(3,1000);
delay(100);
noTone(3);
}
}
}
//.....
lastButtonState = reading;
}
void startDisplay()
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(40,40);
display.println("Blood Oxygen");
display.setTextSize(2);
display.setCursor(40,50);
display.print(perCent);
display.setTextSize(1);
display.print(" %SpO2");
display.display();
}
void loop()
{
buttonChange();
long irValue = particleSensor.getIR();
if (checkForBeat(irValue) == true && ledState == HIGH)
{
display.clearDisplay();
display.display();
tone(3,1000);
delay(100);
noTone(3);
else{
count = count+1;
avgIr = avgIr + irValue;
}
//Get an average IR value over 100 loops
if (count == 100) {
avgIr = avgIr / count;