Gihex HC-SR04
Introduction
This is the library used to access the HC-SR04 ultrasonic sensor. This library inspired by hc-sr04
.
For more detail how to use this library see Example
.
Features
- Measure distance.
- Get last duration ultrasonic wave returned
- Set environment temperature for compensation. Only available if feature
temperature
orhumidity
enabled. - Set environment humidity for compensation. Only available if feature
humidity
enabled.
How to Use?
To use this library, there are several things that must be done, such as:
- Implementing external interrupt (
EXTI
) withRAISING
andFAILING
trigger to the pinecho
(pin microcontroller that connected to the pinecho
HC-SR04 sensor).
let mut echo_pin = gpioa.pa3.into_pull_down_input;
echo_pin.make_interrupt_source;
let mut exti = ctx.device.EXTI;
echo_pin.enable_interrupt;
echo_pin.trigger_on_edge;
- Create an object that impelements trait [
us_timer::TickerUs
]. This object is used to count the number of ticks.
use ;
- Create HC-SR04 object and use it.
let hcsr04 = hc_sr04_new;
let distance=hcsr04.;