max30102c语言,max30102问题
程序如下:#include #include "MAX30105.h"
#include "heartRate.h"
#include "spo2_algorithm.h"
MAX30105 particleSensor;
#define MAX_BRIGHTNESS 255
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format
//To solve this problem, 16-bit MSB of the sampled data will be truncated. Samples become 16-bit data.
uint16_t irBuffer[100]; //infrared LED sensor data
uint16_t redBuffer[100]; //red LED sensor data
#else
uint32_t irBuffer[100]; //infrared LED sensor data
uint32_t redBuffer[100]; //red LED sensor data
#endif
int32_t bufferLength; //data length
int32_t spo2; //SPO2 value
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
int32_t heartRate; //heart rate value
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid
byte pulseLED = 11; //Must be on PWM pin
byte readLED = 13; //Blinks with each data read
const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
byte rates[RATE_SIZE]; //Array of heart rates
byte rateSpot = 0;
long lastBeat = 0; //Time at which the last beat occurred
float beatsPerMinute;
int beatAvg;
void setup()
{
Serial.begin(115200); // initialize serial communication at 115200 bits per second:
pinMode(pulseLED, OUTPUT);
pinMode(readLED, OUTPUT);
// Initialize sensor
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
{
Serial.println(F("MAX30105 was not found. Please check wiring/power."));
while (1);
}
Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion"));
while (Serial.available() == 0) ; //wait until user presses a key
Serial.read();
byte ledBrightness = 60; //Options: 0=Off to 255=50mA
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
int pulseWidth = 411; //Options: 69, 118, 215, 411
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
// 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 loop()
{
bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps
//read the first 100 samples, and determine the signal range
for (byte i = 0 ; i < bufferLength ; i++)
{
while (particleSensor.available() == false) //do we have new data?
particleSensor.check(); //Check the sensor for new data
redBuffer= particleSensor.getRed();
irBuffer= particleSensor.getIR();
particleSensor.nextSample(); //We're finished with this sample so move to next sample
}
//calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
while (1)
{
//dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
for (byte i = 25; i < 100; i++)
{
redBuffer[i - 25] = redBuffer;
irBuffer[i - 25] = irBuffer;
}
//take 25 sets of samples before calculating the heart rate.
for (byte i = 75; i < 100; i++)
{
while (particleSensor.available() == false) //do we have new data?
particleSensor.check(); //Check the sensor for new data
digitalWrite(readLED, !digitalRead(readLED)); //Blink onboard LED with every data read
redBuffer= particleSensor.getRed();
irBuffer= particleSensor.getIR();
long irValue = particleSensor.getIR();
if (checkForBeat(irValue) == true)
{
//We sensed a beat!
long delta = millis() - lastBeat;
lastBeat = millis();
beatsPerMinute = 60 / (delta / 1000.0);
}
particleSensor.nextSample(); //We're finished with this sample so move to next sample
//send samples and calculation result to terminal program through UART
// Serial.print(F("red="));
// Serial.print(redBuffer, DEC);
// Serial.print(F(", ir="));
// Serial.print(irBuffer, DEC);
// Serial.print(F(", HR="));
// Serial.print(heartRate, DEC);
// Serial.print(F(", HRvalid="));
// Serial.print(validHeartRate, DEC);
Serial.print(", BPM=");
Serial.print(beatsPerMinute);
Serial.print(F(", SPO2="));
Serial.print(spo2, DEC);
Serial.print(F(", SPO2Valid="));
Serial.println(validSPO2, DEC);
// if (irValue < 50000)
// Serial.println(" No finger?");
}
//After gathering 25 new samples recalculate HR and SP02
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
}
}
max30102c语言,max30102问题相关推荐
- Go语言的错误异常处理机制及其应用
一.背景 在日常编写golang程序或阅读别人的golang代码时,我们总会看到如下的一堆代码块: xx, err = func(xx) if err != nil {//do sth. to tac ...
- Go 知识点(19)— Go 语言中的野指针
野指针是一种指向内存位置是不可知的指针,一般是由于指针变量在声明时没有初始化所导致的.在 Go语言中,布尔类型的零值为 false,数值类型的零值为 0,字符串类型的零值为 "", ...
- gcc 自动识别的文件扩展名,gcc/g++ -x 选项指定语言,不同 gcc 版本 -std 编译选项支持列表
对于执行 C 或者 C++ 程序,需要借助 gcc(g++)指令来调用 GCC 编译器. 对于以 .c 为扩展名的文件,GCC 会自动将其视为 C 源代码文件 对于以 .cpp 为扩展名的文件,GCC ...
- OpenCV 笔记(07)— Mat 对象输出格式设置(Python 格式、CSV 格式、NumPy 格式、C 语言格式)
首先是下面代码中将要使用的 r 矩阵的定义.需要注意,我们可以通过用 randu 函数产生的随机值来填充矩阵, 需要给定一个上限和下限来确保随机值在期望的范围内. Mat r = Mat(2, 3, ...
- 利用牛顿法求平方根-Go语言实现
牛顿法解释 百度的解释如下: 通俗的解释就是:多数方程不存在求根公式,牛顿提出了一种用迭代来求方程近似根的方法.思路就是不断取切线,用线性方程的根逼近非线性方程f(x)=0f(x)=0f(x)=0的根 ...
- 翻转二叉树 c语言实现 递归 栈 队列
前言 题目比较好理解,就是翻转二叉树 代码 c语言实现 #include<stdio.h> #include<stdlib.h> #include<string.h> ...
- 字符串全排列的问题 python和c语言实现
前言 这是一个的经典的问题 设计一个算法,输出一个字符串字符的全排列. 比如,String = "abc" 输出是"abc","bac",& ...
- 快速排序的递归和非递归实现 c语言版本
代码 挖坑法 解释 选取一个关键字(key)作为枢轴,一般取整组记录的第一个数/最后一个,这里采用选取序列第一个数为枢轴,也是初始的坑位. 设置两个变量i = l;j = r;其中l = 0, r = ...
- c语言中字符串数组的地址存放以及%s输出单个字符导致程序崩溃的问题
代码 总结下c语言中字符串数组的地址存放问题 #include <iostream> using namespace std; #include<bits/stdc++.h>i ...
- 关于C语言中的数组指针、指针数组以及二级指针
概念解释 数组指针:首先它是一个指针,它指向一个数组,即指向数组的指针:在32 位系统下永远是占4 个字节,至于它指向的数组占多少字节,不知道.数组指针指向的是数组中的一个具体元素,而不是整个数组,所 ...
最新文章
- cocos2d-x 2.X for Android中需要使用OpenGL ES 2.0
- 大班体育游戏电子计算机教案,幼儿园大班体育游戏教案《夹球走走走》
- 【读书笔记】.Net并行编程高级教程--Parallel
- 3.5 SE93创建自建表事务码
- 数据集.npy格式与png格式互换
- 为什么不建议学python贴吧_为什么那么多自学Python的后来都放弃了,分析起来就这些原因...
- 如何在JPG或BMP图片上显示输入的订单数据内容,并在报表打印时显示出来,后台数据库是SQL SERVER 2000 ,先谢了.高分!...
- 【解决方案修复谷歌翻译 Windows、macOS】谷歌翻译退出了中国市场不能用了
- 2021-09-13 《鸟叔Linux私房菜》阅读纪录 第一章-Linux是什么如何学习-Linux 是什么Torvalds的Linux 发展
- Spring Boot入门HelloWorld
- 高考录取查询显示内部服务器错误,为什么江苏成人高考成绩查询网页一直打不开...
- 李宏毅ML笔记14:降维/无监督-线性方法
- ThinkPHP教程--20--系统流程
- SpringBoot掌握的差不多了,就剩下一个Actuator没搞定了,本文详细来介绍!!!
- 【毕业设计】基于单片机的红外测距系统设计与实现 - c51 物联网 stm32
- python图像预处理-(二)腐蚀与膨胀
- 使用HorizontalListView仿车来了公交时刻表
- 【无标题】中国电信5G技术大规模天线技术
- Spring @Value默认值
- Lattice Diamond安装与学习
热门文章
- js控制Windows Media Player
- VB.net 调用FFmpeg简单处理视频(类库——6)
- MySQL8安装详细步骤
- unicode字符集和utf-8编码
- 计算机辅助数控编程交互图形,第六章 计算机辅助数控编程.ppt
- 网络工程师面试真题——ACL与IP Prefix的区别
- 解决办法:[sqlserver] Cannot connect to XXXX\SQLEXPRESS
- URPF - 单播逆向路径转发
- 安卓手机如何复制粘贴不重叠_复制的文字粘贴时怎么重叠了 - 卡饭网
- 形式语言与自动机_第二章_语言及文法