Skip to content

Commit

Permalink
tests: added test app for the bh1750fvi driver
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Feb 9, 2016
1 parent 3bf85cb commit 49dd104
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/driver_bh1750/Makefile
@@ -0,0 +1,7 @@
APPLICATION = driver_pir
include ../Makefile.tests_common

USEMODULE += xtimer
USEMODULE += bh1750fvi

include $(RIOTBASE)/Makefile.include
15 changes: 15 additions & 0 deletions tests/driver_bh1750/README.md
@@ -0,0 +1,15 @@
# About
This test application is created for testing/demonstrating the BH1750FVI driver.
It uses the default device parameters as specified in
`drivers/bh1750fvi/include/bh1750fvi_params.h`. To override these setting, you
can simply do this by defining these parameters as compiler flags while uilding,
e.g.:
```
$ CFLAGS="-DBH1750FVI_PARAM_I2C=I2C_DEV(1)"" make all
```

# Usage
Simply flash this example to your board and it will read the sensor value 5
times per second and print the sampled value to STDIO. You can verify the values
by simply covering the sensor or holding it in front of a bright light and see
the change in the sensor readings accordingly.
47 changes: 47 additions & 0 deletions tests/driver_bh1750/main.c
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2016 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 application for the BH1750FVI ambient light sensor driver
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/

#include <stdio.h>

#include "xtimer.h"
#include "bh1750fvi.h"
#include "bh1750fvi_params.h"

#define RATE (200 * MS_IN_USEC) /* 200ms */

int main(void)
{
bh1750fvi_t dev;
uint32_t last = xtimer_now();

puts("BH1750FVI ambient light sensor test\n");

/* initialize the device */
bh1750fvi_init(&dev, (bh1750fvi_params_t *)(&bh1750fvi_params));

/* periodically sample the sensor */
while(1) {
uint16_t val = bh1750fvi_sample(&dev);
printf("value: %5i lux\n", (int)val);
xtimer_usleep_until(&last, RATE);
}

return 0;
}

0 comments on commit 49dd104

Please sign in to comment.