Hello, I'm still trying to troubleshoot my project. Now the problem is that the LCD display does not display the BPM and such and I've had no luck trying to figure out the Serial.write function. When I remove the Serial.write and replace it with lcd.print, nothing gets displayed, but I need the display to update in real time. The code is posted below and any assistance is greatly appreciated.
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <FilterDerivative.h>#include <FilterOnePole.h>
#include <Filters.h>
#include <FilterTwoPole.h>
#include <FloatDefine.h>
#include <RunningStatistics.h>
// initialize the library with the numbers of the interface pins
// If using software SPI (the default case):
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
SoftwareSerial Genotronex(8, 9); // RX, TX
int ledpin = 13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
int nFrames = 36;
int backlight
= 13;
int peakValue = 0;
float amplifiedSignal; //amplified HR signalfloat filteredSignal; //filtered HR signal
int threshold = 160; //FILL IN THIS LINE WITH THE THRESHOLD SIGNAL VALUE THAT YOU'RE GOING TO USE
int heartbeatCount = 0; //variable keeps track of number of heartbeats
int beatsPerMinute; //HR in units of bpm
int numOfHeartbeats = 5; //total number of heartbeats used to calculate heartrate
float startTime; //time in seconds when first heartbeat occurs
float stopTime; //time in seconds when the last heartbeat (numOfHeartbeats) occurs
bool possibleHeartbeat = false; //if the signal is above the threshold, we may have a peak
unsigned long endTime = 0;
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hello");
lcd.display();
delay (2000);
lcd.clear();
lcd.display();
Genotronex.begin(9600);
Genotronex.print("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin, OUTPUT);
}// filter out frequencies below 1 Hz.
float highFilterFrequency = 1;
// create a highpass filter that only keeps frequencies above highFilterFrequency
FilterOnePole filterOneHighpass( HIGHPASS, highFilterFrequency );
// filters out frequenceies greater than 3 Hz.
float lowFilterFrequency = 3;
// create a lowpass filter that only keeps frequencies below lowFilterFrequency
FilterOnePole filterOneLowpass(LOWPASS, lowFilterFrequency);
void loop() {
delay(200);
if (Serial.available()){amplifiedSignal = 100 * analogRead(A0);
filteredSignal = filterOneHighpass.input(filterOneLowpass.input(amplifiedSignal));
//Serial.println(filteredSignal);
//check to see if we have a heart beat
if (filteredSignal > threshold)
possibleHeartbeat = true;
else if (possibleHeartbeat == true && filteredSignal < threshold) {
heartbeatCount += 1;
possibleHeartbeat = false;
//start timing if we have the first heartbeat
if (heartbeatCount == 1)
startTime = millis() / 1000.0; //starting time in seconds
//if we count "numOfHeartbeats" heartbeats, calculate a heartrate
else if (heartbeatCount == numOfHeartbeats) {
stopTime = millis() / 1000.0; //stopping time in seconds
beatsPerMinute = 60 * (numOfHeartbeats - 1) / (stopTime - startTime);
Serial.print("Your HR is : ");
Serial.print(beatsPerMinute);
Serial.println(" bpm");
heartbeatCount = 0;
}
}
else {
lcd.clear();
lcd.display();
for (int z = 0; z < 1000; z++) {
lcd.setCursor(0, 0);
lcd.print("BPM:");
lcd.setCursor(4, 0);
lcd.write(Serial.read(beatsPerMinute));
lcd.display();
if (beatsPerMinute >= 60 && beatsPerMinute <= 110) {
lcd.setCursor(0, 1);
lcd.print("Normal");
lcd.display();
}
else if (beatsPerMinute < 60) {
lcd.setCursor(0, 1);
lcd.print("Abnormally Slow");
lcd.display();
}
else if (beatsPerMinute > 110) {
lcd.setCursor(0, 1);
lcd.print("Keep up the pace");
lcd.display();
}
else if (beatsPerMinute > 190) {
lcd.setCursor(0, 1);
lcd.print("Call an ambulance");
lcd.display();
}
}
lcd.clear();
lcd.display();
}
}
if (Genotronex.available()) {
BluetoothData = Genotronex.read();
if (BluetoothData == '1') { // if number 1 pressed ....
digitalWrite(ledpin, 1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData == '0') { // if number 0 pressed ....
digitalWrite(ledpin, 0);
Genotronex.println("LED On D13 Off ! ");
}
}
}