Blame view

RIOT/tests/driver_bh1750/main.c 1.16 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  /*
   * 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        (200LU * US_PER_MS)      /* 200ms */
  
  int main(void)
  {
      int res;
      bh1750fvi_t dev;
      xtimer_ticks32_t last = xtimer_now();
  
      puts("BH1750FVI ambient light sensor test\n");
  
      /* initialize the device */
      res = bh1750fvi_init(&dev, (bh1750fvi_params_t *)(&bh1750fvi_params));
      if (res != BH1750FVI_OK) {
          puts("error: unable to initialize sensor [I2C initialization error]");
          return 1;
      }
  
      /* periodically sample the sensor */
      while(1) {
          uint16_t val = bh1750fvi_sample(&dev);
          printf("value: %5i lux\n", (int)val);
          xtimer_periodic_wakeup(&last, RATE);
      }
  
      return 0;
  }