Code Monkey home page Code Monkey logo

ultrasonic-library's Introduction

Ultrasonic-Library

Ultrasonic module library for any type of microcontroller

Version : 0.0.0

  • Type : Embedded Software.

  • Support : Any type of microcontroller

  • Program Language : C

  • Properties :

Initialization and de-initialization functions:

- None 

Operation functions:

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);

Macros:

- None 

How to use this library

The Ultrasonic library can be used as follows:

1. Add .h and source file in project.

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()

3. Initialize a External Interrupt in Rising/Falling edge mode

4. Add ISR Handle functions in the External Interrupt Routine, for example:

Ultrasonic_TypeDef Sensor;

void GPIO_ISR_RisingEdge()
{
    Ultrasonic_ISRHandle_Rising(&Sensor);
}

void GPIO_ISR_FallingEdge()
{
    Ultrasonic_ISRHandle_Falling(&Sensor);
}

5. Using operation methods, for example:

Example 1:

#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);
    }
}
   

Test Performed:

  • SRF05
  • SRF04
  • US-026

Developer: Majid Derhambakhsh

ultrasonic-library's People

Contributors

majid-derhambakhsh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.