zinnet yazıcı
/
Our_Code_copy
dszds
main.cpp@0:83277b73a1f8, 2019-07-28 (annotated)
- Committer:
- zinnetyazicii53
- Date:
- Sun Jul 28 08:14:38 2019 +0000
- Revision:
- 0:83277b73a1f8
commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zinnetyazicii53 | 0:83277b73a1f8 | 1 | //#include <Wire.h> |
zinnetyazicii53 | 0:83277b73a1f8 | 2 | /*#include "MAX30102.h" |
zinnetyazicii53 | 0:83277b73a1f8 | 3 | |
zinnetyazicii53 | 0:83277b73a1f8 | 4 | #include "heartRate.h" |
zinnetyazicii53 | 0:83277b73a1f8 | 5 | |
zinnetyazicii53 | 0:83277b73a1f8 | 6 | //MAX30102 particleSensor; |
zinnetyazicii53 | 0:83277b73a1f8 | 7 | |
zinnetyazicii53 | 0:83277b73a1f8 | 8 | |
zinnetyazicii53 | 0:83277b73a1f8 | 9 | void(* resetFunc) (void) = 0; |
zinnetyazicii53 | 0:83277b73a1f8 | 10 | |
zinnetyazicii53 | 0:83277b73a1f8 | 11 | bool nofinger=false; |
zinnetyazicii53 | 0:83277b73a1f8 | 12 | bool programStarted=false; |
zinnetyazicii53 | 0:83277b73a1f8 | 13 | |
zinnetyazicii53 | 0:83277b73a1f8 | 14 | int RATE_SIZE=0; //Increase this for more averaging. 4 is good. |
zinnetyazicii53 | 0:83277b73a1f8 | 15 | int rate[1000]; //Array of heart rates |
zinnetyazicii53 | 0:83277b73a1f8 | 16 | long lastBeat = 0; //Time at which the last beat occurred |
zinnetyazicii53 | 0:83277b73a1f8 | 17 | |
zinnetyazicii53 | 0:83277b73a1f8 | 18 | float beatsPerMinute; |
zinnetyazicii53 | 0:83277b73a1f8 | 19 | int beatAvg; |
zinnetyazicii53 | 0:83277b73a1f8 | 20 | |
zinnetyazicii53 | 0:83277b73a1f8 | 21 | long now=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 22 | int bpm = 0; |
zinnetyazicii53 | 0:83277b73a1f8 | 23 | int mins=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 24 | int ten_secs=10; |
zinnetyazicii53 | 0:83277b73a1f8 | 25 | int avg=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 26 | |
zinnetyazicii53 | 0:83277b73a1f8 | 27 | long t=millis(); |
zinnetyazicii53 | 0:83277b73a1f8 | 28 | void setup() |
zinnetyazicii53 | 0:83277b73a1f8 | 29 | { |
zinnetyazicii53 | 0:83277b73a1f8 | 30 | pc.baud(9600); |
zinnetyazicii53 | 0:83277b73a1f8 | 31 | pc.format(8,SerialBase::None,1); |
zinnetyazicii53 | 0:83277b73a1f8 | 32 | wait(1); |
zinnetyazicii53 | 0:83277b73a1f8 | 33 | pc.printf("Initializing..."); |
zinnetyazicii53 | 0:83277b73a1f8 | 34 | |
zinnetyazicii53 | 0:83277b73a1f8 | 35 | // Initialize sensor |
zinnetyazicii53 | 0:83277b73a1f8 | 36 | if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed |
zinnetyazicii53 | 0:83277b73a1f8 | 37 | { |
zinnetyazicii53 | 0:83277b73a1f8 | 38 | pc.printf"MAX30105 was not found. Please check wiring/power. "); |
zinnetyazicii53 | 0:83277b73a1f8 | 39 | while (1); |
zinnetyazicii53 | 0:83277b73a1f8 | 40 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 41 | pc.printf("Place your index finger on the sensor with steady pressure."); |
zinnetyazicii53 | 0:83277b73a1f8 | 42 | |
zinnetyazicii53 | 0:83277b73a1f8 | 43 | particleSensor.setup(); //Configure sensor with default settings |
zinnetyazicii53 | 0:83277b73a1f8 | 44 | particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running |
zinnetyazicii53 | 0:83277b73a1f8 | 45 | particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED |
zinnetyazicii53 | 0:83277b73a1f8 | 46 | |
zinnetyazicii53 | 0:83277b73a1f8 | 47 | //particleSensor.enableDIETEMPRDY(); //Enable the temp ready interrupt. This is required. |
zinnetyazicii53 | 0:83277b73a1f8 | 48 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 49 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
zinnetyazicii53 | 0:83277b73a1f8 | 50 | void measureTemp(){ |
zinnetyazicii53 | 0:83277b73a1f8 | 51 | float temperature=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 52 | temperature = particleSensor.readTemperature(); |
zinnetyazicii53 | 0:83277b73a1f8 | 53 | pc.printf(" temperatureC="); |
zinnetyazicii53 | 0:83277b73a1f8 | 54 | pc.printf(temperature, 4); |
zinnetyazicii53 | 0:83277b73a1f8 | 55 | return; |
zinnetyazicii53 | 0:83277b73a1f8 | 56 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 57 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
zinnetyazicii53 | 0:83277b73a1f8 | 58 | |
zinnetyazicii53 | 0:83277b73a1f8 | 59 | void check(){ |
zinnetyazicii53 | 0:83277b73a1f8 | 60 | if(!programStarted && RATE_SIZE==4){ |
zinnetyazicii53 | 0:83277b73a1f8 | 61 | programStarted=true; RATE_SIZE=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 62 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 63 | return; |
zinnetyazicii53 | 0:83277b73a1f8 | 64 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 65 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
zinnetyazicii53 | 0:83277b73a1f8 | 66 | void measureBPM(){ |
zinnetyazicii53 | 0:83277b73a1f8 | 67 | long irValue = particleSensor.getIR(); |
zinnetyazicii53 | 0:83277b73a1f8 | 68 | |
zinnetyazicii53 | 0:83277b73a1f8 | 69 | if (checkForBeat(irValue) == true) |
zinnetyazicii53 | 0:83277b73a1f8 | 70 | { |
zinnetyazicii53 | 0:83277b73a1f8 | 71 | //We sensed a beat! |
zinnetyazicii53 | 0:83277b73a1f8 | 72 | long delta = millis() - lastBeat; |
zinnetyazicii53 | 0:83277b73a1f8 | 73 | lastBeat = millis(); |
zinnetyazicii53 | 0:83277b73a1f8 | 74 | |
zinnetyazicii53 | 0:83277b73a1f8 | 75 | beatsPerMinute = 60 / (delta / 1000.0); |
zinnetyazicii53 | 0:83277b73a1f8 | 76 | |
zinnetyazicii53 | 0:83277b73a1f8 | 77 | if (beatsPerMinute < 255 && beatsPerMinute > 20) |
zinnetyazicii53 | 0:83277b73a1f8 | 78 | { |
zinnetyazicii53 | 0:83277b73a1f8 | 79 | check(); |
zinnetyazicii53 | 0:83277b73a1f8 | 80 | rate[RATE_SIZE++]=(byte)beatsPerMinute; |
zinnetyazicii53 | 0:83277b73a1f8 | 81 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 82 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 83 | |
zinnetyazicii53 | 0:83277b73a1f8 | 84 | //Serial.print(ten_secs); |
zinnetyazicii53 | 0:83277b73a1f8 | 85 | //Serial.println("seconds...."); |
zinnetyazicii53 | 0:83277b73a1f8 | 86 | if(millis()-t>=10000){ |
zinnetyazicii53 | 0:83277b73a1f8 | 87 | if(RATE_SIZE==0){ |
zinnetyazicii53 | 0:83277b73a1f8 | 88 | nofinger=true; |
zinnetyazicii53 | 0:83277b73a1f8 | 89 | return; |
zinnetyazicii53 | 0:83277b73a1f8 | 90 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 91 | |
zinnetyazicii53 | 0:83277b73a1f8 | 92 | beatAvg=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 93 | for(int i=0; i<RATE_SIZE; i++){ |
zinnetyazicii53 | 0:83277b73a1f8 | 94 | beatAvg+=rate[i]; |
zinnetyazicii53 | 0:83277b73a1f8 | 95 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 96 | pc.printf("Avg BPM="); |
zinnetyazicii53 | 0:83277b73a1f8 | 97 | pc.printf("%i",beatAvg/RATE_SIZE); |
zinnetyazicii53 | 0:83277b73a1f8 | 98 | t=millis(); |
zinnetyazicii53 | 0:83277b73a1f8 | 99 | ten_secs+=10; |
zinnetyazicii53 | 0:83277b73a1f8 | 100 | mins++; |
zinnetyazicii53 | 0:83277b73a1f8 | 101 | if(mins%6==0){ |
zinnetyazicii53 | 0:83277b73a1f8 | 102 | beatAvg=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 103 | for(int i=0; i<RATE_SIZE; i++){ |
zinnetyazicii53 | 0:83277b73a1f8 | 104 | beatAvg+=rate[i]; |
zinnetyazicii53 | 0:83277b73a1f8 | 105 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 106 | pc.printf(" Avg BPM after a min is="); |
zinnetyazicii53 | 0:83277b73a1f8 | 107 | pc.printf(beatAvg/RATE_SIZE); |
zinnetyazicii53 | 0:83277b73a1f8 | 108 | //measureTemp(); |
zinnetyazicii53 | 0:83277b73a1f8 | 109 | mins=0; |
zinnetyazicii53 | 0:83277b73a1f8 | 110 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 111 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 112 | |
zinnetyazicii53 | 0:83277b73a1f8 | 113 | if (irValue < 50000){ |
zinnetyazicii53 | 0:83277b73a1f8 | 114 | nofinger=true; |
zinnetyazicii53 | 0:83277b73a1f8 | 115 | return; |
zinnetyazicii53 | 0:83277b73a1f8 | 116 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 117 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 118 | int main() |
zinnetyazicii53 | 0:83277b73a1f8 | 119 | { |
zinnetyazicii53 | 0:83277b73a1f8 | 120 | setup(); |
zinnetyazicii53 | 0:83277b73a1f8 | 121 | if(nofinger){ |
zinnetyazicii53 | 0:83277b73a1f8 | 122 | pc.printf(" No finger"); |
zinnetyazicii53 | 0:83277b73a1f8 | 123 | long irValue = particleSensor.getIR(); |
zinnetyazicii53 | 0:83277b73a1f8 | 124 | if (irValue > 50000){ |
zinnetyazicii53 | 0:83277b73a1f8 | 125 | nofinger=false; |
zinnetyazicii53 | 0:83277b73a1f8 | 126 | resetFunc(); |
zinnetyazicii53 | 0:83277b73a1f8 | 127 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 128 | } |
zinnetyazicii53 | 0:83277b73a1f8 | 129 | measureBPM(); |
zinnetyazicii53 | 0:83277b73a1f8 | 130 | //Measure(); |
zinnetyazicii53 | 0:83277b73a1f8 | 131 | }*/ |