Skip to content

Commit f1a5ed6

Browse files
committed
Update Resistance Buffer Reading
If the resistance buffer is not completely filled yet, the buffer reading gets adapted.
1 parent 11b095d commit f1a5ed6

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ void readVoltage() {
6161

6262
uint16_t getVoltageAverage() {
6363
uint16_t avg = 0;
64-
for (int i = 0; i < VOLTAGE_BUFFER_SIZE; i++) {
64+
byte upperBound = voltageBufferFilled ? VOLTAGE_BUFFER_SIZE : voltageBufferIndex;
65+
for (int i = 0; i < upperBound; i++) {
6566
avg += voltageSampleBuffer[i];
6667
}
67-
if (voltageBufferFilled) {
68-
return avg / VOLTAGE_BUFFER_SIZE;
69-
}
70-
return avg / voltageBufferIndex;
68+
return avg / upperBound;
7169
}
7270

7371
// String to calculate the local and device name

0 commit comments

Comments
 (0)