Hi all. Programming is not my strong point. I know the if else statement is fairly basic but I am having some trouble with it. I am building a heart monitor with a warning system. The warning system consists of an LCD, one red LED and a Piezo buzzer. What I want the if else statement to do is - if the heart rate is less than 140 then the LCD will display Regular Heart Rate, the LED and buzzer will stay off. Else the LCD will display WARNING! Irregular Heart Rate. The LED and buzzer will flash and beep at the same rate. Here is the code I have so far. Any help will be greatly appreciated. thank you in advance.
#include "Wire.h"
#include "hrmi_funcs.h"
#include <LiquidCrystal.h>
#define HRMI_HOST_BAUDRATE 9600
#define HRMI_I2C_ADDR 127
#define MAX_IN_BUFFSIZE 16
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char serInStr[MAX_IN_BUFFSIZE]; // Serial input string array
int numEntries = 0; // Number of HR values to request
int numRspchars; // Number of Response chars to read
char i2cRspArray[34]; // I2C response array, sized to read 32 HR values
char hrmi_addr = HRMI_I2C_ADDR; // I2C address to use
int led = 13;
void setup()
{
// Initialize the I2C communication
hrmi_open();
// Initialize the serial interface
Serial.begin(HRMI_HOST_BAUDRATE);
lcd.begin(16, 2);
pinMode(led, OUTPUT);
pinMode(9, OUTPUT);
}
/*
* Arduino main code loop
*/
void loop()
{
// Request a set of heart rate values
hrmiCmdArg(hrmi_addr, 'G', (char) numEntries);
// Get the response from the HRMI
numRspchars = numEntries + 2;
if (hrmiGetData(hrmi_addr, numRspchars, i2cRspArray) != -1) {
// send the results back on the serial interface in ASCII form
Serial.print("Request "); Serial.print(numEntries); Serial.print(" => ");
for (int i=0; i<numRspchars; i++) {
Serial.print(i2cRspArray[i], DEC);
Serial.print(" ");
}
Serial.println();
}
// Setup to do it again
if (++numEntries > 30)
numEntries = 0;
delay(1000); // Delay 1 second between commands
if (???? < 140){
digitalWrite(led, LOW);
lcd.setCursor(0,1);
lcd.print("Regular Heart Rate");
}
else{
lcd.setCursor(0,0);
lcd.print("WARNING!");
lcd.setCursor(0,0);
lcd.print("Irregular Heart Rate");
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(200); // wait for a second
analogWrite(9,128);
delay(500);
digitalWrite(9, LOW);
delay(200);
}
Thank you.