I am trying to use this code but the notation is giving me issues. I keep getting the compile error that this title is named after. I think it might be the use of && <, >. Can these be substituted for something?
#include <MAX3010x.h>
#include "filters.h"
#include <LiquidCrystal.h>
// Sensor (adjust to your sensor type)
MAX30105 sensor;
// set a sampling rate
const auto kSamplingRate = sensor.SAMPLING_RATE_400SPS;
// set a sampling frequency
const float kSamplingFrequency = 400.0;
// set a Finger Detection Threshold and Cooldown
const unsigned long kFingerThreshold = 10000;
const unsigned int kFingerCooldownMs = 500;
// set an Edge Detection Threshold
const float kEdgeThreshold = -2000.0;
// Filters
const float kLowPassCutoff = 5.0;
const float kHighPassCutoff = 0.5;
// Averaging
const bool kEnableAveraging = true;
const int kAveragingSamples = 50;
const int kSampleThreshold = 5;
// for LCD, set the pins connected to display
// here its will be pins 7,8,9,10,11,12
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
// set if else condition to display on serial monitor whether sensor is working or not
if(sensor.begin() && sensor.setSamplingRate(kSamplingRate)) {
// if the sensor detects pulse, print the following message on LCD display
lcd.print("Hello from CityBeat");
}
// if the sensor is not initialized, print the following on LCD
else {
Serial.println("Sensor not found");
while(1);
}
}
// Filter Instances
HighPassFilter high_pass_filter(kHighPassCutoff, kSamplingFrequency);
LowPassFilter low_pass_filter(kLowPassCutoff, kSamplingFrequency);
Differentiator differentiator(kSamplingFrequency);
MovingAverageFilter<kAveragingSamples> averager;
// Timestamp of the last heartbeat
long last_heartbeat = 0;
// Timestamp for finger detection
long finger_timestamp = 0;
bool finger_detected = false;
// Last diff to detect zero crossing
float last_diff = NAN;
bool crossed = false;
long crossed_time = 0;
void loop() {
// read sample on sensor every 1000 milliseconds
auto sample = sensor.readSample(1000);
float current_value = sample.red;
// Detect Finger using raw sensor value
if(sample.red > kFingerThreshold) {
if(millis() - finger_timestamp > kFingerCooldownMs) {
finger_detected = true;
}
}
else {
// Reset values if the finger is removed
differentiator.reset();
averager.reset();
low_pass_filter.reset();
high_pass_filter.reset();
finger_detected = false;
finger_timestamp = millis();
}
if(finger_detected) {
current_value = low_pass_filter.process(current_value);
current_value = high_pass_filter.process(current_value);
float current_diff = differentiator.process(current_value);
// Valid values?
if(!isnan(current_diff) && !isnan(last_diff)) {
// Detect Heartbeat - Zero-Crossing
if(last_diff > 0 && current_diff < 0) {
crossed = true;
crossed_time = millis();
}
if(current_diff > 0) {
crossed = false;
}
// Detect Heartbeat - Falling Edge Threshold
if(crossed && current_diff < kEdgeThreshold) {
if(last_heartbeat != 0 && crossed_time - last_heartbeat > 300) {
// Show Results
int bpm = 60000/(crossed_time - last_heartbeat);
if(bpm > 50 && bpm < 250) {
// Average?
if(kEnableAveraging) {
int average_bpm = averager.process(bpm);
// Show if enough samples have been collected
if(averager.count() > kSampleThreshold) {
// first print output of average heartrate on serial monitor
Serial.print("Heart Rate (avg, bpm): ");
Serial.println(average_bpm);
// then print output of average heartrate on LCD display
lcd.clear();
lcd.print("avg Rate: ");
lcd.print(average_bpm);
lcd.print("bpm");
}
}
else {
// otherwise print output of heartrate on serial monitor
Serial.print("Heart Rate (current, bpm): ");
Serial.println(bpm);
// otherwise print output of heartrate on LCD Display
lcd.clear();
lcd.print(" rate: ");
lcd.println(bpm);
}
}
}
crossed = false;
last_heartbeat = crossed_time;
}
}
last_diff = current_diff;
}
}
Ok thank you guys that helped a lot. The formatting of this file is affecting other lines of code. These line (and similar ones) gives me the error "'HighPassFilter' does not name a type; did you mean 'kHighPassCutoff'?" Do these also need to be decoded?