zinnet yazıcı
/
Our_Code_copy
dszds
Diff: main.cpp
- Revision:
- 0:83277b73a1f8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jul 28 08:14:38 2019 +0000 @@ -0,0 +1,131 @@ +//#include <Wire.h> +/*#include "MAX30102.h" + +#include "heartRate.h" + +//MAX30102 particleSensor; + + +void(* resetFunc) (void) = 0; + +bool nofinger=false; +bool programStarted=false; + +int RATE_SIZE=0; //Increase this for more averaging. 4 is good. +int rate[1000]; //Array of heart rates +long lastBeat = 0; //Time at which the last beat occurred + +float beatsPerMinute; +int beatAvg; + +long now=0; +int bpm = 0; +int mins=0; +int ten_secs=10; +int avg=0; + +long t=millis(); +void setup() +{ + pc.baud(9600); + pc.format(8,SerialBase::None,1); + wait(1); + pc.printf("Initializing..."); + + // Initialize sensor + if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed + { + pc.printf"MAX30105 was not found. Please check wiring/power. "); + while (1); + } + pc.printf("Place your index finger on the sensor with steady pressure."); + + particleSensor.setup(); //Configure sensor with default settings + particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running + particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED + + //particleSensor.enableDIETEMPRDY(); //Enable the temp ready interrupt. This is required. +} + //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +void measureTemp(){ + float temperature=0; + temperature = particleSensor.readTemperature(); + pc.printf(" temperatureC="); + pc.printf(temperature, 4); + return; +} + //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + +void check(){ + if(!programStarted && RATE_SIZE==4){ + programStarted=true; RATE_SIZE=0; + } + return; +} + //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +void measureBPM(){ + long irValue = particleSensor.getIR(); + + if (checkForBeat(irValue) == true) + { + //We sensed a beat! + long delta = millis() - lastBeat; + lastBeat = millis(); + + beatsPerMinute = 60 / (delta / 1000.0); + + if (beatsPerMinute < 255 && beatsPerMinute > 20) + { + check(); + rate[RATE_SIZE++]=(byte)beatsPerMinute; + } + } + + //Serial.print(ten_secs); + //Serial.println("seconds...."); + if(millis()-t>=10000){ + if(RATE_SIZE==0){ + nofinger=true; + return; + } + + beatAvg=0; + for(int i=0; i<RATE_SIZE; i++){ + beatAvg+=rate[i]; + } + pc.printf("Avg BPM="); + pc.printf("%i",beatAvg/RATE_SIZE); + t=millis(); + ten_secs+=10; + mins++; + if(mins%6==0){ + beatAvg=0; + for(int i=0; i<RATE_SIZE; i++){ + beatAvg+=rate[i]; + } + pc.printf(" Avg BPM after a min is="); + pc.printf(beatAvg/RATE_SIZE); + //measureTemp(); + mins=0; + } + } + + if (irValue < 50000){ + nofinger=true; + return; + } +} +int main() +{ + setup(); + if(nofinger){ + pc.printf(" No finger"); + long irValue = particleSensor.getIR(); + if (irValue > 50000){ + nofinger=false; + resetFunc(); + } + } + measureBPM(); + //Measure(); +}*/ \ No newline at end of file