groundFungus:
Where do you actually read the button switch? Don't you need to set the led pin to output?All of those digitalWrites and delays can be replaced by a for loop.
I forgot to add those sorry. Hope you can read through this..
/* This is the sketch for a vital signs monitor intended to senses temperature and heart rate*/
#include <LiquidCrystal.h> //Include LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Connections to arduino pins
/define/
int tempPin = A1;
int TEMPERATURE = 0;
// Pulse Monitor Test Script
int HBSensor = 8;//the heart beat sensor is connected to pin 8 of arduino uno
double alpha = 0.75;
int period = 100;
double change = 0.0;
double minval = 0.0;
int run;//for pushbutton
int LED = 7;// LED connected on this output pin
int HBStart = 6; //button is connected to pin 6 on arduino
/* void setup*/
void setup()
{
/temp setup/
Serial.begin(9600);
/lcd setup/
lcd.begin(16, 2);// lcd display
run = 0; //starts stopped pushbutton
pinMode(HBSensor, INPUT); //heartbeat sensor
pinMode(HBStart, INPUT_PULLUP);//for pushbutton
pinMode (tempPin,INPUT); //temperature sensor
pinMode (LED,OUTPUT);
lcd.clear();//clears LCD display
lcd.print("Current HB : "); //will display the current hb
lcd.setCursor(0,0);//first line of lcd
lcd.print("HB/Min : 0.0 ");
lcd.setCursor(0,1);//second line of lcd
lcd.print("Temp: "); //will display the current temperature reading
lcd.print ("C");//celcius
}
void loop()
{
//instead of having one big loop i divided the multiple loop into three loops with different names which are
loopBUTTON();
loopHR();
loopTEMP();
}
void loopBUTTON ()
//void loop 1 for pushbutton
{
if(run == 0)
{
run = 255;
}
else
{
run = 0;
}
if(run > 0)
{
//code you only run if button was pressed, stops running when button pressed again, so forth...
}
}
//void loop 2 for heartbeat
void loopHR ()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead (HBSensor);//This reads in the value from the analog pin. this is a 10 bit number, and will be between 0 and 1023
// If this value doesn't change, you've connected up
// something wrong
double value = alpha * oldValue + (1 - alpha) * rawValue;// Calculate an average using 75% of the
// previous value and 25% of the new
Serial.print("HB/Min = ");
Serial.print (rawValue);
Serial.print (",");//comma
Serial.println (value);//send out average value and go to next line
oldValue = value;//save average for next iteration
delay (2000);//wait 2 seconds
lcd.setCursor(0,0);//print results
lcd.print(value);
lcd.print(" ");
}
//void loop 3
void loopTEMP ()
{
int val;
val = analogRead(tempPin);//READ THE A1 PIN
float mv = ( val/1024.0)*5000; //MANIPULATE THE VALUE
float cel = mv/10;//DIVIDE BY 10
Serial.print("TEMPERATURE = ");
Serial.print (cel);
Serial.print ("C");
lcd.setCursor(0,1);
lcd.print ("TEMPERATURE");
lcd.print (cel);
lcd.print ("*C");
Serial.println("");
delay (5000);
lcd.setCursor(0,1);
lcd.print("Press Button again.");
if(cel >= 39)
{
//blinks at 5ms intervals for 10 seconds
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
digitalWrite(LED, LOW);
if(cel <= 39)
{
digitalWrite(LED,LOW); //switch LED off
}
}