2014-12-15 17:17:19 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2014-12-15 17:17:19 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-15 17:17:19 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <signal.h>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "adc121c021.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-12-15 17:17:19 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2014-12-15 17:17:19 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2014-12-15 17:17:19 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2014-12-15 17:17:19 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
2014-12-15 17:17:19 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate an ADC121C021 on I2C bus 0
|
2014-12-15 17:17:19 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::ADC121C021 adc(ADC121C021_I2C_BUS, ADC121C021_DEFAULT_I2C_ADDR);
|
2014-12-15 17:17:19 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// An analog sensor, such as a Grove light sensor,
|
|
|
|
// must be attached to the adc
|
|
|
|
// Prints the value and corresponding voltage every 50 milliseconds
|
|
|
|
while (shouldRun) {
|
|
|
|
uint16_t val = adc.value();
|
|
|
|
cout << "ADC value: " << val << " Volts = " << adc.valueToVolts(val) << endl;
|
|
|
|
upm_delay_us(50000);
|
2014-12-15 17:17:19 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2014-12-15 17:17:19 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2014-12-15 17:17:19 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2014-12-15 17:17:19 -07:00
|
|
|
}
|