ESPHome  2023.5.5
ultrasonic_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/gpio.h"
6 
7 namespace esphome {
8 namespace ultrasonic {
9 
11  public:
12  void set_trigger_pin(GPIOPin *trigger_pin) { trigger_pin_ = trigger_pin; }
13  void set_echo_pin(InternalGPIOPin *echo_pin) { echo_pin_ = echo_pin; }
14 
16  void set_timeout_us(uint32_t timeout_us);
17 
18  // ========== INTERNAL METHODS ==========
19  // (In most use cases you won't need these)
21  void setup() override;
22  void dump_config() override;
23 
24  void update() override;
25 
26  float get_setup_priority() const override;
27 
29  void set_pulse_time_us(uint32_t pulse_time_us);
30 
31  protected:
33  static float us_to_m(uint32_t us);
35 
39  uint32_t timeout_us_{};
40  uint32_t pulse_time_us_{};
41 };
42 
43 } // namespace ultrasonic
44 } // namespace esphome
void set_pulse_time_us(uint32_t pulse_time_us)
Set the time in µs the trigger pin should be enabled for in µs, defaults to 10µs (for HC-SR04) ...
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition: gpio.h:66
GPIOPin * trigger_pin_
Helper function to convert the specified distance in meters to the echo duration in µs...
void set_timeout_us(uint32_t timeout_us)
Set the timeout for waiting for the echo in µs.
This class simplifies creating components that periodically check a state.
Definition: component.h:282
void set_echo_pin(InternalGPIOPin *echo_pin)
static float us_to_m(uint32_t us)
Helper function to convert the specified echo duration in µs to meters.
void setup() override
Set up pins and register interval.
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:57