Skip to content
Snippets Groups Projects
Commit 812a4df9 authored by Josef Vágner's avatar Josef Vágner
Browse files

init and add base SW

parent 7805c75d
No related branches found
No related tags found
No related merge requests found
*.DS_Store
# 3D models
Write documentation here!
# PCB design
Write documentation here!
# SW (Programs)
Write documentation here!
SW/SW.ino 0 → 100644
#include <Adafruit_NeoPixel.h>
#define DIN1 2
#define COUNT1 15
Adafruit_NeoPixel line1 = Adafruit_NeoPixel(COUNT1, DIN1, NEO_GRB + NEO_KHZ800);
#define DIN2 3
#define COUNT2 21
Adafruit_NeoPixel line2 = Adafruit_NeoPixel(COUNT2, DIN2, NEO_GRB + NEO_KHZ800);
#define DIN3 4
#define COUNT3 3
Adafruit_NeoPixel line3 = Adafruit_NeoPixel(COUNT3, DIN3, NEO_GRB + NEO_KHZ800);
#define LP_ALPHA 0.1
#define HP_ALPHA 0.9
#define EKG_PIN 28
float lowPassValue = 0;
float highPassValue = 0;
float prevValue = 0;
float HR = 0.0;
// Peak detection parameters
#define WINDOW_SIZE 3
float values[WINDOW_SIZE];
int id = 0;
#define THRESHOLD 0.5 // Adjust threshold as needed
#define MIN_INTERVAL 500 // Minimum time between peaks (in milliseconds)
unsigned long lastPeakTime = 0;
// Function prototypes
float lowPassFilter(float input);
float highPassFilter(float input);
bool detectPeak(float current);
void controlLEDs(float heartRate);
void setup() {
Serial.begin(9600);
delay(1);
pinMode(EKG_PIN, INPUT);
line1.begin();
line1.fill(line1.Color(0, 0, 0), 0, COUNT1);
line1.show();
line2.begin();
line2.fill(line2.Color(0, 0, 0), 0, COUNT2);
line2.show();
line3.begin();
line3.fill(line3.Color(0, 0, 0), 0, COUNT3);
line3.show();
}
float lowPassFilter(float input) {
lowPassValue += LP_ALPHA * (input - lowPassValue);
return lowPassValue;
}
float highPassFilter(float input) {
highPassValue = HP_ALPHA * (highPassValue + input - prevValue);
prevValue = input;
return highPassValue;
}
bool detectPeak(float current) {
values[id] = current;
id = (id + 1) % WINDOW_SIZE;
if (values[(id + 1) % WINDOW_SIZE] > values[id] && values[(id + 1) % WINDOW_SIZE] > values[(id + 2) % WINDOW_SIZE]) {
return true;
}
return false;
}
void controlLEDs(long brightness, float HR) {
uint32_t color;
if (HR < 60) {
color = line1.Color(0, 0, brightness); // Blue for low heart rate
} else if (HR < 100) {
color = line1.Color(0, brightness, 0); // Green for normal heart rate
} else {
color = line1.Color(brightness, 0, 0); // Red for high heart rate
}
line1.fill(color, 0, COUNT1);
line2.fill(color, 0, COUNT2);
line3.fill(color, 0, COUNT3);
line1.show();
line2.show();
line3.show();
}
void loop() {
int rawValue = analogRead(EKG_PIN);
float filteredValue = lowPassFilter(rawValue);
filteredValue = highPassFilter(filteredValue);
// Print filtered value for debugging
// Serial.println(filteredValue);
long brightness = map(filteredValue, -15, 50, 0, 150);
if (filteredValue > THRESHOLD) {
unsigned long currentTime = millis();
if (currentTime - lastPeakTime > MIN_INTERVAL) {
if (detectPeak(filteredValue)) {
lastPeakTime = currentTime;
//Serial.println("Peak detected!");
// Calculate heart rate
static unsigned long previousPeakTime = 0;
if (previousPeakTime != 0) {
HR = 60000.0 / (currentTime - previousPeakTime);
//Serial.print("Heart Rate: ");
Serial.println(HR);
}
previousPeakTime = currentTime;
}
}
}
controlLEDs(brightness, HR);
delay(10); // Adjust delay as needed
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment