|
只有把loop函数里红色那俩行注释掉,心率和血氧的值才有变化,否则一直是0,而两个模块单独运行则没有问题,求解答!
#include <Wire.h>
#include "Wire.h"
#include "MAX30100_PulseOximeter.h"
//#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h> //Include Adafruit GFX Library
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_SSD1306.h> //Include Adafruit OLED Library
#define PIN_BEEP 14
#define ONE_WIRE_BUS 4
#define REPORTING_PERIOD_MS 1000
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
//Adafruit_MLX90614 mlx = Adafruit_MLX90614();
// 初始连接在单总线上的单总线设备
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature tempsensor(&oneWire);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);//Declaring the display name (display)
PulseOximeter pox;
uint32_t tsLastReport = 0;
float bpm=0;
float temp =0;
int spo2 = 0;
void setup()
{
Wire.begin();
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
tempsensor.begin();
pinMode(PIN_BEEP,OUTPUT);
if (!pox.begin()) {
Serial.println("FAILED");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("FAILED");
display.display();
for(;;);
} else {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("SUCCESS");
display.display();
Serial.println("SUCCESS");
}
}
void loop()
{
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("BPM: ");
bpm=pox.getHeartRate();
display.print(bpm);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 33);
display.println("TEMP: ");
tempsensor.requestTemperatures(); // 发送命令获取温度
temp=tempsensor.getTempCByIndex(0);
display.print(temp);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 16);
display.println("Spo2: ");
spo2 = pox.getSpO2();
display.print(spo2);
display.display();
isAlarm(bpm,temp, spo2);
tsLastReport = millis();
}
}
//报警
void isAlarm (float BPM, float TEMP, int SPO2) {
if((BPM==0)&&(TEMP<38)&&(SPO2==0)){
digitalWrite(PIN_BEEP, HIGH);
}
if((BPM==0)&&(TEMP<38)&&(SPO2>=93)){
digitalWrite(PIN_BEEP, HIGH);
}
if((BPM<=100)&&(BPM>=50)&&(TEMP<38)&&(SPO2>=93)){
digitalWrite(PIN_BEEP, HIGH);
}
if((BPM<=100)&&(BPM>=50)&&(TEMP<38)&&(SPO2==0)){
digitalWrite(PIN_BEEP, HIGH);
}
if(BPM>=100){
digitalWrite(PIN_BEEP, LOW);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70, 0);
display.print("WARNING!");
display.display();
}
if((BPM<=50)&&(BPM>0)){
digitalWrite(PIN_BEEP, LOW);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70, 0);
display.print("WARNING!");
display.display();
}
if(TEMP>=38){
digitalWrite(PIN_BEEP, LOW);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70, 33);
display.print("WARNING!");
display.display();
}
if((SPO2<93)&&(SPO2!=0)){
digitalWrite(PIN_BEEP, LOW);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70, 16);
display.print("WARNING!");
display.display();
}
}
|
|