first commit
This commit is contained in:
37
include/drivers/DistanceSensorController.h
Normal file
37
include/drivers/DistanceSensorController.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef DISTANCE_SENSOR_CONTROLLER_H
|
||||
#define DISTANCE_SENSOR_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define DEFAULT_MIN_READ_INTERVAL_DIST 100
|
||||
#define DEFAULT_SAMPLES 3
|
||||
#define MAX_DISTANCE 400
|
||||
|
||||
class DistanceSensorController {
|
||||
private:
|
||||
uint8_t _trigPin;
|
||||
uint8_t _echoPin;
|
||||
unsigned long _lastReadTime;
|
||||
unsigned long _minReadInterval;
|
||||
long _lastDistanceCm;
|
||||
bool _lastReadSuccess;
|
||||
uint8_t _numSamples;
|
||||
unsigned long _timeout;
|
||||
|
||||
long microsecondsToCentimeters(long microseconds);
|
||||
|
||||
long takeMeasurement();
|
||||
|
||||
public:
|
||||
DistanceSensorController(uint8_t trigPin, uint8_t echoPin);
|
||||
void begin();
|
||||
bool read();
|
||||
long getDistanceCm();
|
||||
long getDistanceInch();
|
||||
bool isLastReadSuccessful() const;
|
||||
void setMinReadInterval(unsigned long interval);
|
||||
void setNumSamples(uint8_t samples);
|
||||
void setTimeout(unsigned long timeout);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user