SlideShare a Scribd company logo
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// SPI pin definition for the Mega. Check the SPI page on Arduino website for
more info
#define cs 10
#define dc 9
#define rst 8
#define sda 51
#define scl 52
TFT screen = TFT(cs, dc, rst);// create an instance of the screen library
unsigned long peaktArr[11], pAndt[2][3]; //peaktArr stores the peak values from
pAndt; pAndt stores the values from the sensor which are compared to one another
to determine a peak
float tdiff[10];//array to store time difference between consecutive time
stamps
int i = 0;
int j = 0;
int k = 0;
float inst_f = 0;
int p = 0;
int a = 0;
unsigned long calb;
int xPos = 0;//initial value (position) of the cursor that draws the waveform
void setup(){//the entire code in this loop will only happen 1 time
screen.begin();//initializing the screen
screen.setTextSize(2);//increasing text size 10X
screen.background(0, 0, 255);
unsigned long delayTime = millis();//millis() stores the amount of time in
milliseconds that has passed since it was introduced into the program. This
value is then passed into the variable delayTime
while(millis() - delayTime <= 3000){ // delayTime has a set value and will not
change and the program within the the while loop will run as long the difference
between millis() and delayTime is less than 3000 milliseconds or 3 seconds
screen.setCursor(0,0);///the 1st value in brackets sets the distance from the
left edge of the screen, and the 2nd value sets the distance from the top edge
of the screen
screen.print("Welcome To");
screen.setCursor(0,25);
screen.print("Chelsea's");
screen.setCursor(0,50);
screen.print("Heart Rate");
screen.setCursor(0,75);
screen.print("Device");
}
screen.background(0,0,255);//the 1st value is blue intensity, the 2nd is green
intensity and the 3rd is red intensity. this line makes the background color red
delayTime = millis();
while(millis() - delayTime <= 3000){
screen.setCursor(0,0);
screen.print("Place Finger");
screen.setCursor(0,25);
screen.print("On Sensor");
}
screen.background(0,0,255);
screen.setCursor(0,50);
screen.print("Calibrating");
for(i = 0; i < 3; i++){//read and store 3 values at a time in pAndt
unsigned long delayTime = millis();
pAndt[0][i] = analogRead(A0);//1st row of pAndt stores the sensor values
pAndt[1][i] = millis();// 2nd row of pAndt stores the time stamp of the
sensor values
while (millis() - delayTime <=200){//wait 200 ms before reading the next
sensor values. this means we read 5 values every second
}
}
for(i = 1; i < 2; i++){
if(pAndt[0][i]>pAndt[0][i-1] && pAndt[0][i]>pAndt[0][i+1]){ //compare the
3 values in pAndt to determine a peak
peaktArr[0] = pAndt[1][i];// store the value of i that satisfies the
peak condition
}
}
while(j<11){//the entire code within the while loop repeats until we get 11
values in peaktArr
//replace the values of the 1st column with those of the 2nd column
pAndt[0][0] = pAndt[0][1];//replace the values in row 1
pAndt[1][0] = pAndt[1][1];//replace the values in row 2
//replace the values of the 2nd column with those of the 3rd column
pAndt[0][1] = pAndt[0][2];//replace the values in row 1
pAndt[1][1] = pAndt[1][2];//replace the values in row 2
unsigned long delayTime = millis();//
for(i = 2; i < 3; i++){//read and store 1 value in the 3rd column of pAndt
pAndt[0][i] = analogRead(A0);//1st row of pAndt stores the sensor values
pAndt[1][i] = millis();// 2nd row of pAndt stores the time stamp of the
sensor values
while (millis() - delayTime <=200){//delay in ms before reading the next
value
}
}
for(i = 1; i < 2; i++){
if(pAndt[0][i]>pAndt[0][i-1] && pAndt[0][i]>pAndt[0][i+1]){ //compare the
3 values in pAndt to determine a peak
peaktArr[j++] = pAndt[1][i];// store the value of i that satisfies the
peak condition
}
}
}
for(i = 0; i < 10; i++){
tdiff[k++] = (((float)peaktArr[i+1] - (float)peaktArr[i])/1000);//change
the time values from unsigned long to float, take the difference between
consecutive time values, and convert the result to time in seconds
}
for(i = 0; i < 10; i++){
inst_f = inst_f + (1/tdiff[i]);//convert the time differences to
frequencies and take their sum
}
screen.background(0,0,255);
screen.setCursor(0,0);
screen.print("Heart rate ");
screen.setCursor(0,20);
screen.print((inst_f/10)*60);
screen.setCursor(75,20);
screen.println(" bpm");
while(xPos<=160){
int sensor = analogRead(A0);
int graphHeight = map(sensor,0,682,5,screen.height()/1.5);//map assigns
corresponding values between analog and digital. 0 is the lowest digital
reading,682 is the highest digital reading,5 is the position at which the lowest
reading will appear and screen.height()/1.5 is the position at which the highest
reading will appear
screen.stroke(255,255,255);
screen.line(xPos, (screen.height() - graphHeight), xPos, screen.height() -
graphHeight+3); //screen.height() - graphHeight + 5 affects the thickness of the
line. The bigger the number you add to screen.height() - graphHeight is, the
thicker the line will be
xPos++;
delayTime = millis();
while(millis() - delayTime<=25){//rate at which points are displayed on
screen to plot waveform
}
}
void loop(){
int xPos = 0;
float inst_f = 0;
for(i = 2; i<11; i++){
peaktArr[i-2] = peaktArr[i];//remove the 1st 2 values from the peaktArr array
and shift all the values until the last 2 "spots" in the array are empty
}
j = 9;//start filling peaktArr from index 9 (10th position)
for(i = 1; i<10; i++){
tdiff[i-1] = tdiff[i];//remove the earliest time difference that was
calculated and shift the other values until the last "spot" in the array is
empty
}
while(j<11){
pAndt[0][0] = pAndt[0][1];
pAndt[1][0] = pAndt[1][1];
pAndt[0][1] = pAndt[0][2];
pAndt[1][1] = pAndt[1][2];
unsigned long delayTime = millis();//
for(i = 2; i < 3; i++){
pAndt[0][i] = analogRead(A0);
pAndt[1][i] = millis();
while (millis() - delayTime <=200){
}
}
for(i = 1; i < 2; i++){
if(pAndt[0][i]>pAndt[0][i-1] && pAndt[0][i]>pAndt[0][i+1] /*&& pAndt[0][i]
>= 0.3*hp*/){ //compare the 3 values in pAndt to determine a peak
peaktArr[j++] = pAndt[1][i];// store the value of i that satisfies the
peak condition, and do the comparison above until j is 10
}
}
}
tdiff[9] = (((float)peaktArr[10] - (float)peaktArr[9])/1000);
for(i = 0; i < 10; i++){
inst_f = inst_f + (1/tdiff[i]);
}
screen.background(0,0,255);
screen.setCursor(0,0);
screen.print("Heart rate ");
screen.setCursor(0,20);
screen.print((inst_f/10)*60);
screen.setCursor(75,20);
screen.println(" bpm");
while(xPos<=160){
int sensor = analogRead(A0);
int graphHeight = map(sensor,0,682,5,screen.height()/1.5);
screen.stroke(255,255,255);
screen.line(xPos, (screen.height() - graphHeight), xPos, screen.height() -
graphHeight+3); //screen.height() - graphHeight + 5 affects the thickness of the
line. The bigger the number you add to screen.height() - graphHeight is, the
thicker the line will be
xPos++;
unsigned long delayTime = millis();
while(millis() - delayTime<=25){
}
}
screen.background(0,0,255);
screen.print("Calculating..");
unsigned long delayTime = millis();
while (millis()- delayTime <= 5000){
}
}

More Related Content

What's hot

Code
CodeCode
Better performance through Superscalarity
Better performance through SuperscalarityBetter performance through Superscalarity
Better performance through Superscalarity
Mårten Rånge
 
Cocos2d Performance Tips
Cocos2d Performance TipsCocos2d Performance Tips
Cocos2d Performance Tips
Keisuke Hata
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
PyData
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
Platonov Sergey
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
Mohammad Shaker
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma mohan
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Daniel Luxemburg
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
OdessaJS Conf
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
shin
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
Chaitanya Kn
 
AA-sort with SSE4.1
AA-sort with SSE4.1AA-sort with SSE4.1
AA-sort with SSE4.1
MITSUNARI Shigeo
 
Translating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptTranslating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScript
norbert_kehrer
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
anishgoel
 
Java lejos-multithreading
Java lejos-multithreadingJava lejos-multithreading
Java lejos-multithreading
Mr. Chanuwan
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
Miller Lee
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
Farhan Ab Rahman
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
OdessaJS Conf
 
On using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGA
On using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGAOn using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGA
On using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGA
mjgajda
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
Ankit Kumar
 

What's hot (20)

Code
CodeCode
Code
 
Better performance through Superscalarity
Better performance through SuperscalarityBetter performance through Superscalarity
Better performance through Superscalarity
 
Cocos2d Performance Tips
Cocos2d Performance TipsCocos2d Performance Tips
Cocos2d Performance Tips
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
AA-sort with SSE4.1
AA-sort with SSE4.1AA-sort with SSE4.1
AA-sort with SSE4.1
 
Translating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptTranslating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScript
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
Java lejos-multithreading
Java lejos-multithreadingJava lejos-multithreading
Java lejos-multithreading
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
On using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGA
On using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGAOn using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGA
On using Haskell DSL - CLaSH, to implement a simple digital stopwatch on FPGA
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 

Similar to Senior design project code for PPG

codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
Syed Ghufran Hassan
 
REPORT
REPORTREPORT
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
Snake.c
Snake.cSnake.c
Snake.c
Vijay Singh
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
contact32
 
Open bot
Open bot Open bot
Open bot
Anshuman Dhar
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
Yung-Yu Chen
 
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
Anshuman Dhar
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 
Lab 1 izz
Lab 1 izzLab 1 izz
Lab 1 izz
Sivanraaj
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
kkkseld
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
艾鍗科技
 
Lập trình C
Lập trình CLập trình C
Lập trình C
Viet NguyenHoang
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
annetnash8266
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
جامعة القدس المفتوحة
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
PVS-Studio LLC
 
Vcs16
Vcs16Vcs16
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
The IOT Academy
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 

Similar to Senior design project code for PPG (20)

codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
REPORT
REPORTREPORT
REPORT
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Snake.c
Snake.cSnake.c
Snake.c
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
Open bot
Open bot Open bot
Open bot
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Lab 1 izz
Lab 1 izzLab 1 izz
Lab 1 izz
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
Vcs16
Vcs16Vcs16
Vcs16
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 

Recently uploaded

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 

Recently uploaded (20)

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 

Senior design project code for PPG

  • 1. #include <TFT.h> // Arduino LCD library #include <SPI.h> // SPI pin definition for the Mega. Check the SPI page on Arduino website for more info #define cs 10 #define dc 9 #define rst 8 #define sda 51 #define scl 52 TFT screen = TFT(cs, dc, rst);// create an instance of the screen library unsigned long peaktArr[11], pAndt[2][3]; //peaktArr stores the peak values from pAndt; pAndt stores the values from the sensor which are compared to one another to determine a peak float tdiff[10];//array to store time difference between consecutive time stamps int i = 0; int j = 0; int k = 0; float inst_f = 0; int p = 0; int a = 0; unsigned long calb; int xPos = 0;//initial value (position) of the cursor that draws the waveform void setup(){//the entire code in this loop will only happen 1 time screen.begin();//initializing the screen screen.setTextSize(2);//increasing text size 10X screen.background(0, 0, 255); unsigned long delayTime = millis();//millis() stores the amount of time in milliseconds that has passed since it was introduced into the program. This value is then passed into the variable delayTime while(millis() - delayTime <= 3000){ // delayTime has a set value and will not change and the program within the the while loop will run as long the difference between millis() and delayTime is less than 3000 milliseconds or 3 seconds screen.setCursor(0,0);///the 1st value in brackets sets the distance from the left edge of the screen, and the 2nd value sets the distance from the top edge of the screen screen.print("Welcome To"); screen.setCursor(0,25); screen.print("Chelsea's"); screen.setCursor(0,50); screen.print("Heart Rate"); screen.setCursor(0,75); screen.print("Device"); } screen.background(0,0,255);//the 1st value is blue intensity, the 2nd is green intensity and the 3rd is red intensity. this line makes the background color red delayTime = millis(); while(millis() - delayTime <= 3000){ screen.setCursor(0,0); screen.print("Place Finger"); screen.setCursor(0,25); screen.print("On Sensor"); } screen.background(0,0,255); screen.setCursor(0,50); screen.print("Calibrating"); for(i = 0; i < 3; i++){//read and store 3 values at a time in pAndt unsigned long delayTime = millis(); pAndt[0][i] = analogRead(A0);//1st row of pAndt stores the sensor values pAndt[1][i] = millis();// 2nd row of pAndt stores the time stamp of the sensor values while (millis() - delayTime <=200){//wait 200 ms before reading the next
  • 2. sensor values. this means we read 5 values every second } } for(i = 1; i < 2; i++){ if(pAndt[0][i]>pAndt[0][i-1] && pAndt[0][i]>pAndt[0][i+1]){ //compare the 3 values in pAndt to determine a peak peaktArr[0] = pAndt[1][i];// store the value of i that satisfies the peak condition } } while(j<11){//the entire code within the while loop repeats until we get 11 values in peaktArr //replace the values of the 1st column with those of the 2nd column pAndt[0][0] = pAndt[0][1];//replace the values in row 1 pAndt[1][0] = pAndt[1][1];//replace the values in row 2 //replace the values of the 2nd column with those of the 3rd column pAndt[0][1] = pAndt[0][2];//replace the values in row 1 pAndt[1][1] = pAndt[1][2];//replace the values in row 2 unsigned long delayTime = millis();// for(i = 2; i < 3; i++){//read and store 1 value in the 3rd column of pAndt pAndt[0][i] = analogRead(A0);//1st row of pAndt stores the sensor values pAndt[1][i] = millis();// 2nd row of pAndt stores the time stamp of the sensor values while (millis() - delayTime <=200){//delay in ms before reading the next value } } for(i = 1; i < 2; i++){ if(pAndt[0][i]>pAndt[0][i-1] && pAndt[0][i]>pAndt[0][i+1]){ //compare the 3 values in pAndt to determine a peak peaktArr[j++] = pAndt[1][i];// store the value of i that satisfies the peak condition } } } for(i = 0; i < 10; i++){ tdiff[k++] = (((float)peaktArr[i+1] - (float)peaktArr[i])/1000);//change the time values from unsigned long to float, take the difference between consecutive time values, and convert the result to time in seconds } for(i = 0; i < 10; i++){ inst_f = inst_f + (1/tdiff[i]);//convert the time differences to frequencies and take their sum } screen.background(0,0,255); screen.setCursor(0,0); screen.print("Heart rate "); screen.setCursor(0,20); screen.print((inst_f/10)*60); screen.setCursor(75,20); screen.println(" bpm"); while(xPos<=160){ int sensor = analogRead(A0); int graphHeight = map(sensor,0,682,5,screen.height()/1.5);//map assigns corresponding values between analog and digital. 0 is the lowest digital reading,682 is the highest digital reading,5 is the position at which the lowest reading will appear and screen.height()/1.5 is the position at which the highest reading will appear
  • 3. screen.stroke(255,255,255); screen.line(xPos, (screen.height() - graphHeight), xPos, screen.height() - graphHeight+3); //screen.height() - graphHeight + 5 affects the thickness of the line. The bigger the number you add to screen.height() - graphHeight is, the thicker the line will be xPos++; delayTime = millis(); while(millis() - delayTime<=25){//rate at which points are displayed on screen to plot waveform } } void loop(){ int xPos = 0; float inst_f = 0; for(i = 2; i<11; i++){ peaktArr[i-2] = peaktArr[i];//remove the 1st 2 values from the peaktArr array and shift all the values until the last 2 "spots" in the array are empty } j = 9;//start filling peaktArr from index 9 (10th position) for(i = 1; i<10; i++){ tdiff[i-1] = tdiff[i];//remove the earliest time difference that was calculated and shift the other values until the last "spot" in the array is empty } while(j<11){ pAndt[0][0] = pAndt[0][1]; pAndt[1][0] = pAndt[1][1]; pAndt[0][1] = pAndt[0][2]; pAndt[1][1] = pAndt[1][2]; unsigned long delayTime = millis();// for(i = 2; i < 3; i++){ pAndt[0][i] = analogRead(A0); pAndt[1][i] = millis(); while (millis() - delayTime <=200){ } } for(i = 1; i < 2; i++){ if(pAndt[0][i]>pAndt[0][i-1] && pAndt[0][i]>pAndt[0][i+1] /*&& pAndt[0][i] >= 0.3*hp*/){ //compare the 3 values in pAndt to determine a peak peaktArr[j++] = pAndt[1][i];// store the value of i that satisfies the peak condition, and do the comparison above until j is 10 } } } tdiff[9] = (((float)peaktArr[10] - (float)peaktArr[9])/1000); for(i = 0; i < 10; i++){ inst_f = inst_f + (1/tdiff[i]); } screen.background(0,0,255); screen.setCursor(0,0); screen.print("Heart rate "); screen.setCursor(0,20); screen.print((inst_f/10)*60); screen.setCursor(75,20); screen.println(" bpm"); while(xPos<=160){ int sensor = analogRead(A0); int graphHeight = map(sensor,0,682,5,screen.height()/1.5); screen.stroke(255,255,255);
  • 4. screen.line(xPos, (screen.height() - graphHeight), xPos, screen.height() - graphHeight+3); //screen.height() - graphHeight + 5 affects the thickness of the line. The bigger the number you add to screen.height() - graphHeight is, the thicker the line will be xPos++; unsigned long delayTime = millis(); while(millis() - delayTime<=25){ } } screen.background(0,0,255); screen.print("Calculating.."); unsigned long delayTime = millis(); while (millis()- delayTime <= 5000){ } }