Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:4800e2f494f1, 2020-01-21 (annotated)
- Committer:
- the_nabil
- Date:
- Tue Jan 21 16:04:23 2020 +0000
- Revision:
- 1:4800e2f494f1
- Parent:
- 0:030060e88177
pulsesensor
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| salvolicitra | 0:030060e88177 | 1 | #include "mbed.h" |
| salvolicitra | 0:030060e88177 | 2 | #include "PulseSensor.h" |
| the_nabil | 1:4800e2f494f1 | 3 | #include "USBSerial.h" |
| salvolicitra | 0:030060e88177 | 4 | |
| the_nabil | 1:4800e2f494f1 | 5 | USBSerial pc; |
| the_nabil | 1:4800e2f494f1 | 6 | DigitalOut led(PC_8); |
| salvolicitra | 0:030060e88177 | 7 | PulseSensor sensor; |
| the_nabil | 1:4800e2f494f1 | 8 | InterruptIn button(PC_13); |
| salvolicitra | 0:030060e88177 | 9 | |
| salvolicitra | 0:030060e88177 | 10 | int result; |
| salvolicitra | 0:030060e88177 | 11 | int len = 20; |
| the_nabil | 1:4800e2f494f1 | 12 | int values; |
| the_nabil | 1:4800e2f494f1 | 13 | int count; |
| the_nabil | 1:4800e2f494f1 | 14 | int trash; |
| salvolicitra | 0:030060e88177 | 15 | int myBPM; |
| salvolicitra | 0:030060e88177 | 16 | |
| the_nabil | 1:4800e2f494f1 | 17 | |
| salvolicitra | 0:030060e88177 | 18 | void pressed(){ |
| salvolicitra | 0:030060e88177 | 19 | pc.printf("Your data are been sent\r\n"); |
| salvolicitra | 0:030060e88177 | 20 | } |
| salvolicitra | 0:030060e88177 | 21 | |
| salvolicitra | 0:030060e88177 | 22 | void sendDataToProcessing(char symbol, int data){ |
| salvolicitra | 0:030060e88177 | 23 | if(symbol == 'B') { |
| the_nabil | 1:4800e2f494f1 | 24 | if(::count<len){ |
| salvolicitra | 0:030060e88177 | 25 | result = data<50?50:(data>120?120:data); |
| salvolicitra | 0:030060e88177 | 26 | //pc.printf("\rLoading"); |
| the_nabil | 1:4800e2f494f1 | 27 | ::count++; |
| salvolicitra | 0:030060e88177 | 28 | //for(int i=0;i<(j%4);++i) pc.printf(" ."); |
| salvolicitra | 0:030060e88177 | 29 | if(result<51 || result >119) trash++; |
| salvolicitra | 0:030060e88177 | 30 | else values+=result; |
| salvolicitra | 0:030060e88177 | 31 | |
| salvolicitra | 0:030060e88177 | 32 | } |
| the_nabil | 1:4800e2f494f1 | 33 | if(::count==len){ |
| salvolicitra | 0:030060e88177 | 34 | myBPM=values/(len-trash); |
| salvolicitra | 0:030060e88177 | 35 | if(myBPM == 0){//if the result is composed only |
| salvolicitra | 0:030060e88177 | 36 | pc.printf("\rOps, something was wrong, I restart the measurement\r\n"); |
| the_nabil | 1:4800e2f494f1 | 37 | led=0; ::count=0;values=0;trash=0; |
| salvolicitra | 0:030060e88177 | 38 | } |
| salvolicitra | 0:030060e88177 | 39 | else{ |
| salvolicitra | 0:030060e88177 | 40 | led = 1; |
| salvolicitra | 0:030060e88177 | 41 | pc.printf("\rYour average BPM are: %d\r\n[Black]\trestart the measurement\r\n[Blue]\tconfirm the data\r\n",myBPM); |
| salvolicitra | 0:030060e88177 | 42 | button.fall(&pressed); |
| the_nabil | 1:4800e2f494f1 | 43 | ::count++; |
| salvolicitra | 0:030060e88177 | 44 | } |
| salvolicitra | 0:030060e88177 | 45 | } |
| salvolicitra | 0:030060e88177 | 46 | } |
| salvolicitra | 0:030060e88177 | 47 | } |
| salvolicitra | 0:030060e88177 | 48 | |
| the_nabil | 1:4800e2f494f1 | 49 | |
| salvolicitra | 0:030060e88177 | 50 | int main() { |
| the_nabil | 1:4800e2f494f1 | 51 | //pc.baud(115200); |
| the_nabil | 1:4800e2f494f1 | 52 | wait(1); |
| the_nabil | 1:4800e2f494f1 | 53 | |
| salvolicitra | 0:030060e88177 | 54 | pc.printf("\r\n+++++++++++++++++++++++++++++++++++++++++++++++"); |
| the_nabil | 1:4800e2f494f1 | 55 | pc.printf("\r\nStart to initialize the process\n"); |
| the_nabil | 1:4800e2f494f1 | 56 | |
| the_nabil | 1:4800e2f494f1 | 57 | |
| the_nabil | 1:4800e2f494f1 | 58 | led=0; ::count=0; trash=0; values=0; |
| the_nabil | 1:4800e2f494f1 | 59 | PulseSensor sensor(A1, sendDataToProcessing); |
| salvolicitra | 0:030060e88177 | 60 | while(1) { |
| salvolicitra | 0:030060e88177 | 61 | sensor.start(); |
| the_nabil | 1:4800e2f494f1 | 62 | wait(1); |
| salvolicitra | 0:030060e88177 | 63 | } |
| the_nabil | 1:4800e2f494f1 | 64 | |
| salvolicitra | 0:030060e88177 | 65 | } |