Continuing the discussion from How can I run BLYNK_WRITE in a loop?:
Before creating the topic
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/
- Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
• Add your sketch code.Code should be formatted as example below.
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 100
#include <SoftwareSerial.h>
SoftwareSerial portTwo(15, 13); //TX,RX
char auth[] = "zfdfML-j0uRZGO2OZMI5H87B1vUS1zSD"; // You should get Auth Token in the Blynk App.
char ssid[] = "Ajay_Home"; // Your WiFi credentials.
char pass[] = "Alph@##1307";
BlynkTimer timer;
PulseOximeter pox;
uint32_t tsLastReport = 0;
int SpO2 = 0;
int bt_status ;
char sbuffer[30], ch;
unsigned char pos;
int read1 = 0;
int read2 = 0;
int read3 = 0;
int pinValue ;
//BLYNK_CONNECTED() {
// //get data stored in virtual pin V0 from server
// Blynk.syncVirtual(V6);
//}
BLYNK_WRITE(V6)
{
int pinValue = param.asInt();
Serial.println(pinValue);
}
char mygetchar(void)
{
while (!portTwo.available());
return portTwo.read();
}
void onBeatDetected()
{
Serial.println("Beat!");
}
void Spo2(void) {
pox.update();
SpO2 = pox.getSpO2();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("SpO2:");
Serial.print(SpO2);
Serial.print("%");
Serial.println();
Blynk.virtualWrite(V4, SpO2);
tsLastReport = millis();
}
}
void Blood(void) {
ch = mygetchar();
if (ch == 0x0A)
{
pos = 0; // buffer position reset for next reading
read1 = ((sbuffer[1] - '0') * 100) + ((sbuffer[2] - '0') * 10) + (sbuffer[3] - '0');
read2 = ((sbuffer[6] - '0') * 100) + ((sbuffer[7] - '0') * 10) + (sbuffer[8] - '0');
read3 = ((sbuffer[11] - '0') * 100) + ((sbuffer[12] - '0') * 10) + (sbuffer[13] - '0');
Serial.println("*****************");
Serial.print("SYSTOLIC:");
Serial.print(read1);
Serial.print('\n');
Serial.print("DYSTOLIC:");
Serial.print(read2);
Serial.print('\n');
Serial.print("PULSE");
Serial.print(read3);
Serial.print('\n');
Serial.println("*****************");
Blynk.virtualWrite(V1, read1);
Blynk.virtualWrite(V2, read2);
Blynk.virtualWrite(V3, read2);
}
else { //store serial data to buffer
sbuffer[pos] = ch;
pos++;
}
}
void Both_sens(void) {
if (pinValue == 0) {
Spo2();
}
else {
Blood();
}
}
void setup() {
Serial.begin(9600);
portTwo.begin(9600);
Blynk.begin(auth, ssid, pass);
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
// timer.setInterval(1000, Blood);
timer.setInterval(10, Both_sens);
}
void loop() {
Blynk.run();
timer.run();
}
hello there I am working a project I wanted to switch between two functions. in the above code I used button widget for switching but it executing once only … see the above “’'Both_sens” function it excuites once when I dump the code to esp , and I even tried Blynk.syncVirtual();
it was showing correct status of the button but in both_sens
function if and else condition not working … please help me with this