What are the use of these functions and how can I optimize my code?

I would like to know how each of the following functions work and whether they are all in-built functions or can I change function names or variable names used in the below code?
Also, how can I optimize or change the code so that I can reduce the plagiarism in the code? Please help.

  1. BlynkTimer timer
  2. #define REPORTING_PERIOD_MS 1000
  3. PulseOximeter pox;
  4. uint32_t tsLastReport = 0;
  5. onBeatDetected()
  6. timer.setInterval(1000L, sendUptime);
  7. pox.setOnBeatDetectedCallback(onBeatDetected);
  8. sendUptime()
  9. pox.update();
  10. Blynk.run();
  11. timer.run();
  12. tsLastReport = millis();

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth = “pxtEz9lOymh8PEz4O9WE0N8mahp5aG-s”;
char ssid = “ONEPLUS”;
char pass = “qwertyuiop”;

int n;

#include <Wire.h>
#include “MAX30100_PulseOximeter.h”

#define REPORTING_PERIOD_MS 1000

PulseOximeter pox;

uint32_t tsLastReport = 0;

void onBeatDetected()
{
//Serial.print("HEART BEAT DETECTED ");
}

void setup()
{

Serial.begin(115200);

Serial.print(“Initializing pulse oximeter…”);

Blynk.begin(auth, ssid, pass);

pinMode(16,OUTPUT);
pinMode(5,OUTPUT);
timer.setInterval(1000L, sendUptime);

if (!pox.begin()) {
Serial.println(“FAILED”);
for( ; ; ) ;
} else {
Serial.println(“SUCCESS”);
}

pox.setOnBeatDetectedCallback(onBeatDetected);
}

void sendUptime()
{
Blynk.virtualWrite(V1, n);
}
void loop()
{
// Make sure to call update as fast as possible
pox.update();
Blynk.run();
timer.run();

if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print(“Heart rate:”);
Serial.print(pox.getHeartRate());
if (pox.getHeartRate()>80) {

Serial.println(“READ DATA FROM MQ3”);

n=analogRead(A0);
Serial.println(n);

}

Serial.print(“bpm / SpO2:”);
Serial.print(pox.getSpO2());
Serial.println("%");

tsLastReport = millis();
}
}

shikhxr:
Also, how can I optimize or change the code so that I can reduce the plagiarism in the code? Please help.

That's easy. Start from scratch and write your own code!

I would that's why I wanted to learn about the functions of above statements (1 - 12). Also whether they're in-built or can I change them?

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please tell us your electronics, programming, arduino, hardware experience?

What is the project that you are trying to make?

Thanks… Tom… :slight_smile:

if you don't see the function definition in the sketch it comes from the included libraries.
most of the method calls (9 10 11) - the ones with objectName.methodName() are from the libraries.
So you must study the library files to learn what's going on there.

Most of them aren’t functions.

  1. BlynkTimer timer
    BlynkTimer is a class name, not a variable. ‘timer’ is the name of the class instance.

  2. #define REPORTING_PERIOD_MS 1000
    Is a pre-processor macro definition. Don’t use the pre-processor if you don’t understand it. It adds nothing you couldn’t have done by writing the code out longhand. Remove it.

  3. PulseOximeter pox;
    see 1.

  4. uint32_t tsLastReport = 0;
    Declares as 32 bit (4 byte) unsigned integer type named tsLastReport.

  5. onBeatDetected()
    Well done, a function name.

  6. timer.setInterval(1000L, sendUptime);
    A call to a function on the timer class with some arguments.

  7. pox.setOnBeatDetectedCallback(onBeatDetected);
    See 6.

  8. sendUptime()
    See 5.

  9. pox.update();
    See 6. Although one with no arguments.

  10. Blynk.run();
    See 9.

  11. timer.run();
    See 9.

  12. tsLastReport = millis();
    tsLastReport is a variable.

Suggest learning to write your own code. Then you won’t have to copy someone else’s in its entirety, and you may learn something in the progress.

Also please learn to use [​code]code tags[​/code] when posting to the forum.

Thank you so much. I really appreciate the help.

Also apart from what has been said that sketch will not run properly. It is based on the Blynk App. when using the Blynk App you have to keep your void loop() clean meaning the only 2 functions should be:

Blynk.run();
timer.run();

That is the whole point of the Blynktimer, which is similar in function to simple timer. With the the current loop you will flood the Blynk server and automatically thrown off.