Using Blynk in multiple files

Hello,

I thought I would show an example of how I got Blynk to work in multiple files. Normally, if you try to put #include "src/Blynk/BlynkEdgent.h" in multiple locations, it will throw a compilation error. A way to call Blynk from multiple files can be done by creating a class in a header file and defining the references in the ino file instead of a cpp file. Now, you can instantiate BlynkUpdater in any extra file and call virtualWrites from them indirectly.

In the below example, loop indirectly calls a Blynk.virtualWrite.

Project.ino

// Blynk defines
#define BLYNK_TEMPLATE_ID "TMPLrUQ96ZKJ"
#define BLYNK_DEVICE_NAME "Robotic Farm"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG

#include "src/Blynk/BlynkEdgent.h"

void setup() {
    Serial.begin(115200);
    BlynkEdgent.begin();
}

void loop() {
	extra_file.myFunc();
}

BlynkUpdater::BlynkUpdater(){}

void BlynkUpdater::updateApp() {  
    Blynk.virtualWrite(V2, var);
}

BlynkUpdater.h

#include "Arduino.h"
class BlynkUpdater {
public:
    BlynkUpdater();
    void updateApp(); // updates app with certain data
};

ExtraFile.cpp

void ExtraFile::myFunc() {
	blynk_updater.updateApp(); // magic
}