20 lines
404 B
C++
20 lines
404 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 int scan() {
|
|
return sonar.convert_cm(sonar.ping_median());
|
|
}
|
|
};
|