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:
2026-06-17 00:03:17 +02:00
parent 23d5003788
commit c053a296a5
3 changed files with 51 additions and 18 deletions
+4 -1
View File
@@ -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();
};