File tree 1 file changed +10
-4
lines changed
examples/Example3_HeartRate
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 17
17
18
18
MAX30105 particleSensor;
19
19
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
21
22
byte rateSpot = 0 ;
22
23
long lastBeat = 0 ; // Time at which the last beat occurred
23
24
@@ -35,6 +36,8 @@ void setup()
35
36
Serial.println (" Place your index finger on the sensor with steady pressure." );
36
37
37
38
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
38
41
}
39
42
40
43
void loop ()
@@ -58,13 +61,13 @@ void loop()
58
61
Serial.print (beatsPerMinute);
59
62
60
63
rates[rateSpot++] = (byte)beatsPerMinute; // Store this reading in the array
61
- rateSpot %= 8 ; // Wrap variable
64
+ rateSpot %= RATE_SIZE ; // Wrap variable
62
65
63
66
// Take average of readings
64
67
int beatAvg = 0 ;
65
- for (byte x = 0 ; x < 8 ; x++)
68
+ for (byte x = 0 ; x < RATE_SIZE ; x++)
66
69
beatAvg += rates[x];
67
- beatAvg /= 8 ;
70
+ beatAvg /= RATE_SIZE ;
68
71
69
72
Serial.print (" Avg BPM: " );
70
73
Serial.println (beatAvg);
@@ -74,6 +77,9 @@ void loop()
74
77
Serial.println (" Getting reading" );
75
78
}
76
79
}
80
+
81
+ particleSensor.nextSample (); // We're finished with this sample so move to next sample
82
+
77
83
}
78
84
}
79
85
You can’t perform that action at this time.
0 commit comments