SlideShare una empresa de Scribd logo
1 de 4
#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){
}
}

Más contenido relacionado

La actualidad más candente

Better performance through Superscalarity
Better performance through SuperscalarityBetter performance through Superscalarity
Better performance through SuperscalarityMårten Rånge
 
Cocos2d Performance Tips
Cocos2d Performance TipsCocos2d Performance Tips
Cocos2d Performance TipsKeisuke 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 2014PyData
 
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
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma 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_nosoluitonshin
 
Translating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptTranslating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptnorbert_kehrer
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureanishgoel
 
Java lejos-multithreading
Java lejos-multithreadingJava lejos-multithreading
Java lejos-multithreadingMr. 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++AMPMiller Lee
 
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 FPGAmjgajda
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 

La actualidad más candente (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 a 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 controllerSyed Ghufran Hassan
 
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.pdfshreeaadithyaacellso
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfcontact32
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for SpeedYung-Yu Chen
 
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.pdfforwardcom41
 
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 .docxgordienaysmythe
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1kkkseld
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver艾鍗科技
 
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.docxannetnash8266
 
شرح مقرر البرمجة 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++ codePVS-Studio LLC
 
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 programmingThe 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 .pdfRahul04August
 

Similar a 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
 

Último

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 

Último (20)

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 

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){ } }