mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/srf04: test application for srf04 driver
This commit is contained in:
parent
b24de4a22a
commit
071b8dfa98
9
tests/driver_srf04/Makefile
Normal file
9
tests/driver_srf04/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD ?= nrf52dk
|
||||
|
||||
RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
USEMODULE += srf04
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
17
tests/driver_srf04/README.md
Normal file
17
tests/driver_srf04/README.md
Normal file
@ -0,0 +1,17 @@
|
||||
tests/driver_srf04
|
||||
================
|
||||
This example shows the usage of an srf04 module.
|
||||
The application uses a timer and two gpio pins.
|
||||
The module is an ultrasonic range finder with a small protocol [1]:
|
||||
- trigger pin is raised high for 10 us by calling trigger function
|
||||
- after a sample period of 50 ms the value can be read out
|
||||
|
||||
[1] www.robot-electronics.co.uk/htm/srf04tech.htm
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Build, flash and start the application:
|
||||
|
||||
export BOARD=your_board
|
||||
make flash term
|
48
tests/driver_srf04/main.c
Normal file
48
tests/driver_srf04/main.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Test for srf04 ultra sonic range finder driver
|
||||
*
|
||||
* @author Semjon Kerner <semjon.kerner@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "srf04_params.h"
|
||||
#include "srf04.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("SRF04 range finder example");
|
||||
|
||||
srf04_t dev;
|
||||
if (srf04_init(&dev, &srf04_params[0]) != SRF04_OK) {
|
||||
puts("Error: initializing");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int distance = srf04_get_distance(&dev);
|
||||
if (distance < SRF04_OK) {
|
||||
puts("Error: no valid data available");
|
||||
} else {
|
||||
printf("D: %d mm\n", distance);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user