Ultrasonic module library for any type of microcontroller
- None
Ultrasonic_ScanTypeDef Ultrasonic_GetScanStatus(Ultrasonic_TypeDef *Ultrasonic);
Ultrasonic_OBJStatusTypeDef Ultrasonic_GetObjectStatus(Ultrasonic_TypeDef *Ultrasonic);
void Ultrasonic_GetDistance(Ultrasonic_TypeDef *Ultrasonic, float *DistanceCM, float *DistanceINCH);
/* ::::: ISR Handling ::::: */
void Ultrasonic_ISRHandle_Rising(Ultrasonic_TypeDef *Ultrasonic);
void Ultrasonic_ISRHandle_Falling(Ultrasonic_TypeDef *Ultrasonic);
- None
2. Initialize a timer (16bit or 32bit) with 1MHz frequency and add GetTick function in 'ultrasonic_conf.h', for example:
/* ~~~~~~~~~~~~~~~ Include files ~~~~~~~~~~~~~~~ */
/* Timer header */
#include "timer.h"
/* ~~~~~~~~~~~~~~~~~~ Options ~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~ Microsecond Timer ~~~~~~~~ */
#define __UltrasonicTimer_GetTick() Timer1_GetTick()
Ultrasonic_TypeDef Sensor;
void GPIO_ISR_RisingEdge()
{
Ultrasonic_ISRHandle_Rising(&Sensor);
}
void GPIO_ISR_FallingEdge()
{
Ultrasonic_ISRHandle_Falling(&Sensor);
}
#include <timer.h>
#include <stdio.h>
#include <ultrasonic.h>
Ultrasonic_TypeDef Sensor;
void GPIO_ISR_RisingEdge()
{
Ultrasonic_ISRHandle_Rising(&Sensor);
}
void GPIO_ISR_FallingEdge()
{
Ultrasonic_ISRHandle_Falling(&Sensor);
}
int main(void)
{
float distanceCM = 0;
float distanceINCH = 0;
char msg[20] = {0};
while (1)
{
Ultrasonic_GetDistance(&Sensor, &distanceCM, &distanceINCH);
HAL_Delay(100);
sprintf(msg ,"Distance:%fcm, %finch\r\n", distanceCM, distanceINCH);
HAL_UART_Transmit(&huart6, (uint8_t *)msg, strlen(msg), 100);
}
}
- SRF05
- SRF04
- US-026