Smartcar Shield
|
#include <SR04.hpp>
Public Member Functions | |
SR04 (Runtime &runtime, uint8_t triggerPin, uint8_t echoPin, unsigned int maxDistance=smartcarlib::constants::sr04::kDefaultMaxDistance) | |
Constructs an SR04 ultrasonic sensor. More... | |
unsigned int | getDistance () override |
Gets the distance measured by the sensor in centimeters. More... | |
unsigned int | getMedianDistance (uint8_t iterations=smartcarlib::constants::sr04::kDefaultIterations) override |
Gets the median distance from the specified number of measurements. More... | |
Public Member Functions inherited from DistanceSensor | |
virtual | ~DistanceSensor ()=default |
The SR04 (aka SRF05) is an inexpensive ultrasonic sensor controllable over two digital pins.
For a more advanced solution (faster readings, not using pulseIn
, non-blocking measurements etc) please use the NewPing library.
SR04::SR04 | ( | Runtime & | runtime, |
uint8_t | triggerPin, | ||
uint8_t | echoPin, | ||
unsigned int | maxDistance = smartcarlib::constants::sr04::kDefaultMaxDistance |
||
) |
Constructs an SR04 ultrasonic sensor.
runtime | The runtime environment you want to run the class for |
triggerPin | The pin to produce the trigger signal |
echoPin | The pin to receive the echo signal |
maxDistance | The maximum measurement distance in centimeters |
Example:
|
overridevirtual |
Gets the distance measured by the sensor in centimeters.
Calling this might trigger a new measurement by the sensor.
0
if an error has occured, otherwise the measured distance in centimetersExample:
Implements DistanceSensor.
Definition at line 40 of file SR04.cpp.
|
overridevirtual |
Gets the median distance from the specified number of measurements.
iterations | Number of measurements to conduct (at most kMaxMedianMeasurements ) |
0
or larger than kMaxMedianMeasurements
Example:
Implements DistanceSensor.
Definition at line 61 of file SR04.cpp.