dev #1
@ -3,34 +3,34 @@
|
|||||||
class DistSensor {
|
class DistSensor {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int trigPin;
|
int trig_pin;
|
||||||
int echoPin;
|
int echo_pin;
|
||||||
const int ULTRASONIC_CM_FACTOR = 58;
|
const int ULTRASONIC_CM_FACTOR = 58;
|
||||||
|
|
||||||
void make_measurement(){
|
void make_measurement(){
|
||||||
digitalWrite(this->trigPin, HIGH);
|
digitalWrite(this->trig_pin, HIGH);
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
digitalWrite(this->trigPin, LOW);
|
digitalWrite(this->trig_pin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int duration;
|
int duration;
|
||||||
float default_distance;
|
float default_distance;
|
||||||
|
|
||||||
DistSensor(int trigPin, int echoPin, float default_distance){
|
DistSensor(int trig_pin, int echo_pin, float default_distance){
|
||||||
this->trigPin = trigPin;
|
this->trig_pin = trig_pin;
|
||||||
this->echoPin = echoPin;
|
this->echo_pin = echo_pin;
|
||||||
this->default_distance = default_distance;
|
this->default_distance = default_distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure_pins(){
|
void configure_pins(){
|
||||||
pinMode(this->trigPin, OUTPUT);
|
pinMode(this->trig_pin, OUTPUT);
|
||||||
pinMode(this->echoPin, INPUT);
|
pinMode(this->echo_pin, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_duration(){
|
int get_duration(){
|
||||||
this->make_measurement();
|
this->make_measurement();
|
||||||
this->duration = pulseIn(this->echoPin, HIGH);
|
this->duration = pulseIn(this->echo_pin, HIGH);
|
||||||
return this->duration;
|
return this->duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user