Skip to content

Commit f62a957

Browse files
committed
Small changes to heartrate example
1 parent 7a14787 commit f62a957

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

examples/Example3_HeartRate/Example3_HeartRate.ino

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
MAX30105 particleSensor;
1919

20-
byte rates[8]; //Array of heart rates
20+
const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
21+
byte rates[RATE_SIZE]; //Array of heart rates
2122
byte rateSpot = 0;
2223
long lastBeat = 0; //Time at which the last beat occurred
2324

@@ -35,6 +36,8 @@ void setup()
3536
Serial.println("Place your index finger on the sensor with steady pressure.");
3637

3738
particleSensor.setup(0x7F); //Configure sensor. Use 25mA for LED drive
39+
particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low
40+
particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
3841
}
3942

4043
void loop()
@@ -58,13 +61,13 @@ void loop()
5861
Serial.print(beatsPerMinute);
5962

6063
rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array
61-
rateSpot %= 8; //Wrap variable
64+
rateSpot %= RATE_SIZE; //Wrap variable
6265

6366
//Take average of readings
6467
int beatAvg = 0;
65-
for(byte x = 0 ; x < 8 ; x++)
68+
for(byte x = 0 ; x < RATE_SIZE ; x++)
6669
beatAvg += rates[x];
67-
beatAvg /= 8;
70+
beatAvg /= RATE_SIZE;
6871

6972
Serial.print(" Avg BPM: ");
7073
Serial.println(beatAvg);
@@ -74,6 +77,9 @@ void loop()
7477
Serial.println("Getting reading");
7578
}
7679
}
80+
81+
particleSensor.nextSample(); //We're finished with this sample so move to next sample
82+
7783
}
7884
}
7985

0 commit comments

Comments
 (0)