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

Driver code for the ultrasonic sensor. More...

#include <stdbool.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include "pico/time.h"
#include "pico/types.h"
#include "hardware/gpio.h"
#include "ultrasonic/ultrasonic.h"
Include dependency graph for ultrasonic.c:

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

Driver code for the ultrasonic sensor.

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: