Blame view

RIOT/tests/driver_mq3/main.c 1.27 KB
fb11e647   vrobic   reseau statique a...
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
53
54
55
56
57
58
59
60
61
  /*
   * Copyright (C) 2014 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 MQ-3 alcohol sensor driver
   *
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   *
   * @}
   */
  
  #include <stdio.h>
  
  #include "xtimer.h"
  #include "mq3.h"
  #include "periph_conf.h"
  #include "periph/adc.h"
  
  #ifndef MQ3_ADC_LINE
  #error "MQ3_ADC_LINE is not specified"
  #endif
  
  int main(void)
  {
      mq3_t dev;
      int res;
  
      puts("MQ-3 alcohol sensor test application\n");
      printf("Initializing MQ-3 sensor at ADC_LINE(%i)...   ", (int)MQ3_ADC_LINE);
      res = mq3_init(&dev, MQ3_ADC_LINE);
      if (res == 0) {
          puts("[ok]\n");
      }
      else {
          puts("[failed]");
          return 1;
      }
  
      puts("Will now read and print the sensor twice a second:");
      while (1) {
          int raw, ppm, alc_a, alc_b;
          raw = mq3_read_raw(&dev);
          ppm = mq3_read(&dev);
          alc_a = ppm / 1000;
          alc_b = ppm - (alc_a * 1000);
  
          printf("RAW: %4i, per mille: %1i.%03i\n", raw, alc_a, alc_b);
  
          xtimer_usleep(500 * 1000);
      }
      return 0;
  }