Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
firmware
boards
breezy
breezystm32
examples
mb1242
mb1242read.c
Go to the documentation of this file.
1
/*
2
mb1242read.c : read values from MaxBotix MB1242 I^2C sonar
3
4
Don't forget to supply external power to the board!
5
6
Copyright (C) 2016 Simon D. Levy
7
8
This file is part of BreezySTM32.
9
10
BreezySTM32 is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
14
15
BreezySTM32 is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
19
20
You should have received a copy of the GNU General Public License
21
along with BreezySTM32. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
24
#include <
breezystm32.h
>
25
26
static
bool
sonar_present
;
27
28
void
setup
(
void
)
29
{
30
i2cInit
(
I2CDEV_2
);
31
delay
(500);
32
sonar_present
=
mb1242_init
();
33
}
34
35
void
loop
(
void
)
36
{
37
mb1242_async_update
();
38
delay
(25);
39
LED1_TOGGLE
;
40
if
(
mb1242_present
() ||
sonar_present
)
41
{
42
float
distance
=
mb1242_async_read
();
43
printf
(
"distance = %d.%dm\n"
, (uint32_t)distance, (uint32_t)(distance*1000)%1000);
44
}
45
else
46
printf
(
"no sonar\n"
);
47
}
i2cInit
void i2cInit(I2CDevice index)
Definition:
drv_i2c.c:420
printf
#define printf
Definition:
printf.h:119
mb1242_async_update
void mb1242_async_update()
Definition:
drv_mb1242.c:76
sonar_present
static bool sonar_present
Definition:
mb1242read.c:26
loop
void loop(void)
Definition:
mb1242read.c:35
mb1242_init
bool mb1242_init()
Definition:
drv_mb1242.c:57
mb1242_present
bool mb1242_present()
Definition:
drv_mb1242.c:69
distance
static float distance
Definition:
drv_sen13680.c:34
setup
void setup(void)
Definition:
mb1242read.c:28
breezystm32.h
LED1_TOGGLE
#define LED1_TOGGLE
Definition:
drv_system.h:51
mb1242_async_read
float mb1242_async_read()
Definition:
drv_mb1242.c:99
I2CDEV_2
Definition:
drv_i2c.h:26
delay
void delay(uint32_t ms)
Definition:
system.c:98
rosflight_firmware
Author(s): Daniel Koch
, James Jackson
autogenerated on Wed Jul 3 2019 19:59:25