Skip to content

Commit 6efd637

Browse files
author
dirk.koehler
committed
added new examples for average measurement
1 parent da098f7 commit 6efd637

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Examples/HCSR04example/HCSR04example.ino

+7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ void loop() {
2424
Serial.print(sensor.getDistance());
2525
Serial.print(" mm");
2626

27+
Serial.println("\nAverage of 30 measurements defined manually:");
28+
Serial.print(sensor.getDistance(true,30));
29+
Serial.print(" mm");
30+
2731
Serial.println("\nObstacle in given range of 500 mm found with average option on:");
2832
Serial.print(sensor.getObstacle(500));
2933

34+
Serial.println("\nObstacle in given range of 500 mm found with average option on and 30 measurements:");
35+
Serial.print(sensor.getObstacle(500,true,30));
36+
3037
Serial.println("\nObstacle in given range of 500 mm found with average option off:");
3138
Serial.print(sensor.getObstacle(500,false));
3239
delay(1000);

HCSR04.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int HCSR04::getDistance(boolean average = true, int countAverageMeasurements = 1
7676
boolean HCSR04::getObstacle(int range, boolean average = true, int countAverageMeasurements = 10)
7777
{
7878
int distance = getDistance(average,countAverageMeasurements);
79+
//check if in distance and if measurement is not zero by timeout
7980
if (distance <= range && distance != 0)
8081
{
8182
return true;

0 commit comments

Comments
 (0)