2016-01-14 12:14:06 +01:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2017-01-17 16:44:05 +01:00
|
|
|
#define RATE (200LU * US_PER_MS) /* 200ms */
|
2016-01-14 12:14:06 +01:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2016-11-17 22:58:19 +01:00
|
|
|
int res;
|
2016-01-14 12:14:06 +01:00
|
|
|
bh1750fvi_t dev;
|
2016-07-05 21:32:44 +02:00
|
|
|
xtimer_ticks32_t last = xtimer_now();
|
2016-01-14 12:14:06 +01:00
|
|
|
|
|
|
|
puts("BH1750FVI ambient light sensor test\n");
|
|
|
|
|
|
|
|
/* initialize the device */
|
2019-01-03 23:12:21 +01:00
|
|
|
res = bh1750fvi_init(&dev, &bh1750fvi_params[0]);
|
2016-11-17 22:58:19 +01:00
|
|
|
if (res != BH1750FVI_OK) {
|
|
|
|
puts("error: unable to initialize sensor [I2C initialization error]");
|
|
|
|
return 1;
|
|
|
|
}
|
2016-01-14 12:14:06 +01:00
|
|
|
|
|
|
|
/* periodically sample the sensor */
|
|
|
|
while(1) {
|
|
|
|
uint16_t val = bh1750fvi_sample(&dev);
|
|
|
|
printf("value: %5i lux\n", (int)val);
|
2016-07-07 16:15:33 +02:00
|
|
|
xtimer_periodic_wakeup(&last, RATE);
|
2016-01-14 12:14:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|