SoftwareSerial and Analog Loop Help

I have two different programs that wanted to merge in the void loop section and it doesn’t execute just like what i wanted to, because I’m new to this arduino program.

First, I have a BP device with UART that outputs three parameters in ASCII code.
I used SoftwareSerial to print the exact values from the BP Device into the Serial monitor.

#include <SoftwareSerial.h>
SoftwareSerial BPSerial(2, 3);

void setup() 
{
  Serial.begin(9600);
  while (!Serial) 
  {
    ;
  }

  Serial.println("Blood Pressure Reading");
  Serial.println("Systolic, Diastolic, Pulse");

  BPSerial.begin(9600);
}

void loop() 
{

  if (BPSerial.available()) 
  {
    Serial.write(BPSerial.read());
  }
}

Second, I have temperature Sensor using lm35
my code is working and the loop consist of:
getting samples with interval of time,
when 10 samples were recorded, it computes it average and print it to serial monitor, together with the 10 samples before.

void loop()
{

  for(int startRead = 0; startRead <= BEGIN_ARRAY; startRead++);
    {
      Serial.println("");
      Serial.print("readings[");
      Serial.print(sRead);
      Serial.print("]=");
    
      int temp1 = analogRead(A0);
      float mv = ( temp1/1024.0)*5000; 
      float cel = mv/10;
    
      Serial.print(cel);
      Serial.print("\t\t total=");
    
      total = total + cel;
      Serial.print(total);
      sRead++;
      delay(1000);
    }
 
  
  if (sRead == BEGIN_ARRAY + 1)
    {
      average = total/BEGIN_ARRAY;
      Serial.println("");
      Serial.print("Average=");
      Serial.print(average);
      Serial.println("");
      
  } 
}

Can someone help me on how to merge this two loops into one with two values (average temp and the BP parameters) will be displayed on the same serial monitor?
I already tried the “SerialPort.listen” command but nothing happens.

Im using arduino atmega328 chip.
Thanks!

-alvin

Have a look at this Simple Merge Demo and then have a go at merging your programs. If it doesn't work post your latest attempt.

...R

Hi Sir Robin, I tried merging the loops of two sketches just like what you did, but my temperature code is looping infinite and the values from my serial bp was also shown but each character from the bp was not intact, if i stop the loop of the temperature, the loop on the bp will not be executed using the while(1) command. But, luckily i found my answers by experimenting with the help of your thread you posted above. I isolate the loop of the temperature and made a function and call it on the setup() since i have the condition for 10 samples only. The bp loop code was remained in the loop() function and works normally. I already satisfied on what i saw on the serial monitor.

And sir, may i ask on how to store the values that being serial read from the BP? the values of for example --> 114, 110, 078 (9 numbers + 2 commas + 2 spaces = 13 characters), i wanted this data to be printed..

i wanted to store the numbers, commas, and spaces for future purposes.

iamalvinsitri: I tried merging the loops of two sketches

I did ask you to post your code. Without that, how can I help?

And no 'Sir' thank you - I am not Royalty.

...R