INF2004-Project v0.1
 
Loading...
Searching...
No Matches
ultrasonic.h File Reference

Header file for the ultrasonic sensor driver. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ULTRASONIC_PULSE_TO_CM(x)   (x / 29. / 2.)
 
#define ULTRASONIC_PULSE_TO_IN(x)   (x / 74. / 2.)
 
#define ULTRASONIC_TIMEOUT   26100
 Timeout in cycles.
 
#define ULTRASONIC_TRIG_PULSE_US   10
 Trigger pulse width in us.
 

Functions

uint64_t ultrasonic_get_cm (uint trig_pin, uint echo_pin)
 Get the distance to an object in centimetres. More...
 
uint64_t ultrasonic_get_in (uint trig_pin, uint echo_pin)
 Get the distance to an object in inches. More...
 
void ultrasonic_init_pins (uint trig_pin, uint echo_pin)
 Initalises the pins for the ultrasonic sensor. More...
 

Detailed Description

Header file for the ultrasonic sensor driver.

Author
Ang Jia Yu
Version
0.1
Date
2023-10-29

Function Documentation

◆ ultrasonic_get_cm()

uint64_t ultrasonic_get_cm ( uint  trig_pin,
uint  echo_pin 
)

Get the distance to an object in centimetres.

Parameters
[in]trig_pinTrigger pin for the ultrasonic sensor.
[in]echo_pinEcho pin for the ultrasonic sensor.
Returns
uint64_t The distance to an object in centimetres.

References ULTRASONIC_PULSE_TO_CM.

Here is the caller graph for this function:

◆ ultrasonic_get_in()

uint64_t ultrasonic_get_in ( uint  trig_pin,
uint  echo_pin 
)

Get the distance to an object in inches.

Parameters
[in]trig_pinTrigger pin for the ultrasonic sensor.
[in]echo_pinEcho pin for the ultrasonic sensor.
Returns
uint64_t The distance to an object in inches.

References ULTRASONIC_PULSE_TO_IN.

Here is the caller graph for this function:

◆ ultrasonic_init_pins()

void ultrasonic_init_pins ( uint  trig_pin,
uint  echo_pin 
)

Initalises the pins for the ultrasonic sensor.

Parameters
[in]trig_pinTrigger pin for the ultrasonic sensor.
[in]echo_pinEcho pin for the ultrasonic sensor.
Initialises the trigger and echo pins, and sets a ISR on the echo pin to
measure the pulse width.
Here is the caller graph for this function: