mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
65 lines
1.3 KiB
C
65 lines
1.3 KiB
C
|
/*
|
||
|
* 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 "vtimer.h"
|
||
|
#include "mq3.h"
|
||
|
#include "periph_conf.h"
|
||
|
#include "periph/adc.h"
|
||
|
|
||
|
#ifndef MQ3_ADC
|
||
|
#error "MQ3_ADC is not specified"
|
||
|
#endif
|
||
|
#ifndef MQ3_CHAN
|
||
|
#error "MQ3_CHAN 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_%i, channel %i... ", MQ3_ADC, MQ3_CHAN);
|
||
|
res = mq3_init(&dev, MQ3_ADC, MQ3_CHAN);
|
||
|
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);
|
||
|
|
||
|
vtimer_usleep(500 * 1000);
|
||
|
}
|
||
|
return 0;
|
||
|
}
|