c053a296a5
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.
21 lines
289 B
C++
21 lines
289 B
C++
#pragma once
|
|
#include <Arduino.h>
|
|
|
|
class Sonar {
|
|
public:
|
|
Sonar(int sharedPin, long maxDistCm = 400);
|
|
|
|
long measure();
|
|
|
|
long getDistance() const;
|
|
|
|
private:
|
|
int _trigPin;
|
|
int _echoPin;
|
|
bool _singlePinMode;
|
|
long _maxDistCm;
|
|
long _lastDistance;
|
|
|
|
long _measureSinglePin();
|
|
};
|