Code
Code
Code
#include <math.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define OLED_RESET -1 // This is a dummy pin, as the display I have only has 4 Pins-
SDA,SCL,GND,Vcc...
// Set the Screen for the Pulse display
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
String strArr[15];
uint32_t last =0;
//BlynkTimer timer;
// VARIABLES
int blinkPin = LED_BUILTIN; // pin to blink led at each beat
//int fadePin = 12; // 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, val,temp; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 123; // holds the time between beats, must be seeded!
volatile boolean fever = 0, ECG = 0;
int mx = 0;
// For the display
int x;
int y[LENGTH];
/*
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0, V1);
}
BLYNK_WRITE(V0)
{
//KEkwh = param[0].asDouble();
}
BLYNK_WRITE(V1)
{
//LOADkwh = param[0].asDouble();
}
*/
void clearY()
{
for (int i = 0; i < LENGTH; i++)
{
y[i] = -1;
}
}
void drawY()
{
display.drawPixel(0, y[0], SH110X_WHITE);
for (int i = 1; i < LENGTH; i++)
{
if (y[i] != -1)
{
display.drawLine(i - 1, y[i - 1], i, y[i], SH110X_WHITE);
} else
{
break;
}
}
}
void setup()
{
Serial.begin(9600); // we agree to talk fast!
Wire.begin();
display.begin(0x3C, true); // initialize with the I2C addr 0x3C (for the 128x64)
delay(20);
// Clear the buffer.
display.clearDisplay();
x = 0;
clearY();
pinMode(blinkPin, OUTPUT); // pin that will blink to your heartbeat!
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,28);
display.print("DUET");
display.display();
delay(1000);
}
void loop()
{
Blynk.run();
///////
String rxString = "";
if (Serial.available()) {
//Keep looping until there is something in the buffer.
while (Serial.available()) {
//Delay to allow byte to arrive in input buffer.
delay(2);
//Read a single character from the buffer.
char ch = Serial.read();
//Append that single character to a string.
rxString += ch;
}
int stringStart = 0;
int arrayIndex = 0;
for (int i = 0; i < rxString.length(); i++) {
//Get character and check if it's our "special" character.
if (rxString.charAt(i) == ',') {
//Clear previous values from array.
strArr[arrayIndex] = "";
//Save substring into array.
strArr[arrayIndex] = rxString.substring(stringStart, i);
//Set new string starting point.
stringStart = (i + 1);
arrayIndex++;
}
}
//Put values from the array into the variables.
Signal = int(strArr[0].toInt());
IBI = int(strArr[1].toInt());
BPM = int(strArr[2].toInt());
temp = int(strArr[3].toInt());
}
///////
// VARIABLES
int blinkPin = LED_BUILTIN; // pin to blink led at each beat
//int fadePin = 12; // pin to do fancy classy fading blink at each beat
//int fadeRate = 0; // used to fade LED on with PWM on fadePin
String msg="";
// these variables are volatile because they are used during the interrupt service routine!
int BPM=0; // used to hold the pulse rate
int SpO2=0; // holds the incoming raw data
int ECG = 000; // holds the time between beats, must be seeded!
int temp = 0;
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.
// For the display
int x;
int y[LENGTH];
void setup() {
Serial.begin(9600);
// Initialize sensor
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
}
void loop() {
// Read from the sensor
pox.update();