Add single‑pin Sonar support with periodic reading
Implemented Sonar constructor to use a single shared pin, added mode flag and helper method for single‑pin measurements. Updated measure() to select the appropriate implementation and added timeout to pulseIn. Integrated periodic sonar updates in the main loop, tracking last update time and toggling a seatBelts flag based on distance thresholds.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
class Sonar {
|
||||
public:
|
||||
Sonar(int trigPin, int echoPin, long maxDistCm = 400);
|
||||
Sonar(int sharedPin, long maxDistCm = 400);
|
||||
|
||||
long measure();
|
||||
|
||||
@@ -12,6 +12,9 @@ public:
|
||||
private:
|
||||
int _trigPin;
|
||||
int _echoPin;
|
||||
bool _singlePinMode;
|
||||
long _maxDistCm;
|
||||
long _lastDistance;
|
||||
|
||||
long _measureSinglePin();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user