merging two arduino programs

Hi friends.
We have to combine arduino programs, one of pulse sensor with LCD that is working fine and the second of temperature senor with LCD.
We tried to merge these programs and we ask you for help in merging them.

this is the temp program:

// include the library code:
#include <Wire.h>
int temp_address = 79;
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

byte degree[8] =
{
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
};

void setup() {
//Create Serial Object (9600 Baud)
Serial.begin(9600);
//Create a Wire Object
Wire.begin();
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“Body Temperature”);
//Make celsius characters
// lcd.createChar(0, degree);
}
void loop() {
Wire.beginTransmission(temp_address); //Start talking
Wire.write(0); //Ask for Register zero
Wire.endTransmission(); //Complete Transmission
Wire.requestFrom(temp_address, 1); //Request 1 Byte
while(Wire.available() == 0); //wait for response
int c = Wire.read(); // Get the temp in c
Serial.print(c);
Serial.println(“C,”);
lcd.setCursor(0,1);
lcd.print(c);
lcd.write(byte(0));
lcd.print(“C”);
delay(500);
}

this is the pulse sensor program:

// VARIABLES
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin

// these variables are volatile because they are used during the interrupt service routine!
volatile int BPM; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // holds the time between beats, must be seeded!
volatile boolean Pulse = false; // true when pulse wave is high, false when it’s low
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
// AND APPLY THAT VOLTAGE TO THE A-REF PIN
analogReference(EXTERNAL);
}

void loop(){
sendDataToProcessing(‘S’, Signal); // send Processing the raw Pulse Sensor data
if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
fadeRate = 255; // Set ‘fadeRate’ Variable to 255 to fade LED with pulse
sendDataToProcessing(‘B’,BPM); // send heart rate with a ‘B’ prefix
sendDataToProcessing(‘Q’,IBI); // send time between beats with a ‘Q’ prefix
QS = false; // reset the Quantified Self flag for next time
}

ledFadeToBeat();

delay(520); // take a break
}

void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}

void sendDataToProcessing(char symbol, int data ){
//Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
// Serial.println(data); // the data to send culminating in a carriage return
Serial.println(BPM);
}

and this is the merged program :
// VARIABLES
// include the library code:
#include <Wire.h>
int temp_address = 79;
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
byte degree[8] =
{
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
};
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin

// these variables are volatile because they are used during the interrupt service routine!
volatile int BPM; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // holds the time between beats, must be seeded!
volatile boolean Pulse = false; // true when pulse wave is high, false when it’s low
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(9600); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
// AND APPLY THAT VOLTAGE TO THE A-REF PIN
analogReference(EXTERNAL);
//Create Serial Object (9600 Baud)
Serial.begin(9600);
//Create a Wire Object
Wire.begin();
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“B_Temp”);
//Make celsius characters
lcd.createChar(0, degree);
}
void loop(){
sendDataToProcessing(‘S’, Signal); // send Processing the raw Pulse Sensor data
if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
fadeRate = 255; // Set ‘fadeRate’ Variable to 255 to fade LED with pulse
sendDataToProcessing(‘B’,BPM); // send heart rate with a ‘B’ prefix
sendDataToProcessing(‘Q’,IBI); // send time between beats with a ‘Q’ prefix
QS = false; // reset the Quantified Self flag for next time
}

ledFadeToBeat();

delay(520); // take a break
}

void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
Wire.beginTransmission(temp_address); //Start talking
Wire.write(0); //Ask for Register zero
Wire.endTransmission(); //Complete Transmission
Wire.requestFrom(temp_address, 1); //Request 1 Byte
while(Wire.available() == 0); //wait for response
int c = Wire.read(); // Get the temp in c
Serial.print(c);
Serial.println(“C,”);
lcd.setCursor(0,1);
lcd.print(c);
lcd.write(byte(0));
lcd.print(“C”);
}

void sendDataToProcessing(char symbol, int data ){
//Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
// Serial.println(data); // the data to send culminating in a carriage return
Serial.print(BPM); // symbol prefix tells Processing what type of data is coming
Serial.println(“BPM”); // the data to send culminating in a carriage return
lcd.setCursor(8,1);
lcd.print(BPM);
lcd.setCursor(8,0);
lcd.print(“BPM”);
}

The pulse rate is very high and does not reflect the real pulse rate.
What is the problem ?
please help us soon! Thank you ! :0

Please put those sketches in code tags: the # icon above the ;) and :sweat_smile:. Those are almost impossible to read, and if you tag the code,

it will look
{
like this
}

Meanwhile, I did notice that the LCD uses pin 5 and so is fadePin

What are the requirements for the combined program? Without know that, there is no way to combine two programs.

If you do know the requirements, and you do understand what each is doing, combining them is trivial.