#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address 0x27, 20 column and 4 rows
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
double dat_s[100] = { // sampled recorded data single pulse
0.11, 0.06, 0.48, 0.62, 0.21, 0.13, 0.05, 0.07, 0.05, 0.44,
0.14, 0.08, 0.05, 0.02, 0.02, 0.51, 0.13, 0.11, 0.06, 0.00,
0.05, 0.62, 0.23, 0.13, 0.05, 0.02, 0.10, 0.49, 0.12, 0.06,
0.05, 0.00, 0.40, 0.46, 0.14, 0.09, 0.00, 0.03, 0.52, 0.31,
0.13, 0.05, 0.04, 0.00, 0.67, 0.28, 0.13, 0.09, 0.05, 0.08,
0.83, 0.40, 0.29, 0.11, 0.10, 0.16, 0.96, 0.57, 0.38, 0.17,
0.10, 0.09, 1.00, 0.65, 0.43, 0.21, 0.11, 0.11, 0.75, 0.84,
0.35, 0.26, 0.14, 0.05, 0.11, 0.90, 0.41, 0.32, 0.13, 0.10,
0.05, 0.84, 0.35, 0.15, 0.09, 0.04, 0.06, 0.59, 0.14, 0.14,
0.02, 0.04, 0.81, 0.45, 0.22, 0.08, 0.02, 0.44, 0.76, 0.27
};
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(0, 0); // move cursor the first row
lcd.print("HUMAN PULSE PROJECT!"); // print message at the first row
lcd.setCursor(0, 1); // move cursor to the second row
lcd.print(" HAMDARD UNIVERSITY"); // print message at the second row
lcd.setCursor(6, 2); // move cursor to the third row
lcd.print("PAKISTAN"); // print message at the third row
lcd.setCursor(4, 3); // move cursor to the fourth row
lcd.print("(C)2021-2025"); // print message the fourth row
}
void loop() {
// count events: rising, falling, and no change
int rising = 0, falling = 0, no_change = 0;
for (int i = 1; i < 100; i++)
{
if (dat_s[i] > dat_s[i - 1])
rising++;
else if (dat_s[i] < dat_s[i - 1])
falling++;
else no_change++;
}
display.clearDisplay();
display.drawRect(0, 0, 128, 64, WHITE);
for (int i=0; i<100; i++)
{
int x = i+15;
int y = 55 - dat_s[i] * 50;
display.drawPixel(x, y, WHITE);
display.display();
}
lcd.clear();
lcd.setCursor(0, 0); lcd.print("HUMAN PULSE PROJECT!");
lcd.setCursor(0, 1); lcd.print("COUNT RISING : ");
lcd.setCursor(16,1); lcd.print(rising);
lcd.setCursor(0, 2); lcd.print("COUNT FALLING : ");
lcd.setCursor(16,2); lcd.print(falling);
lcd.setCursor(0, 3); lcd.print("COUNT NO CHANGE: ");
lcd.setCursor(17,3); lcd.print(no_change);
delay(1000);
}