20 lines
387 B
C++
20 lines
387 B
C++
#pragma once
|
|
|
|
#include "GenericSensor.h"
|
|
#include <NewPing.h>
|
|
|
|
#define MAX_DISTANCE 200
|
|
#define TRIGGER_PIN PIN_B3
|
|
#define ECHO_PIN PIN_B4
|
|
|
|
class SonarSensor : public GenericSensor {
|
|
private:
|
|
NewPing sonar{TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE};
|
|
public:
|
|
SonarSensor(short id) : GenericSensor(id) {}
|
|
|
|
unsigned long scan() {
|
|
return sonar.ping_median();
|
|
}
|
|
};
|