2014-12-19 15:17:36 -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-19 15:17:36 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-19 15:17:36 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
|
|
|
#include "upm_utilities.h"
|
2016-09-01 16:32:49 -07:00
|
|
|
#include "vdiv.hpp"
|
2014-12-19 15:17:36 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
bool shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2014-12-19 15:17:36 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2014-12-19 15:17:36 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2014-12-19 15:17:36 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
2014-12-19 15:17:36 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate a Grove Voltage Divider sensor on analog pin A0
|
|
|
|
upm::VDiv vDiv(0);
|
2014-12-19 15:17:36 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// collect data and output measured voltage according to the setting
|
|
|
|
// of the scaling switch (3 or 10)
|
|
|
|
while (shouldRun) {
|
|
|
|
unsigned int val = vDiv.value(100);
|
|
|
|
float gain3val = vDiv.computedValue(3, val);
|
|
|
|
float gain10val = vDiv.computedValue(10, val);
|
|
|
|
cout << "ADC value: " << val << " Gain 3: " << gain3val << "v Gain 10: " << gain10val << "v"
|
|
|
|
<< endl;
|
2014-12-19 15:17:36 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(1);
|
2014-12-19 15:17:36 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2014-12-19 15:17:36 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2014-12-19 15:17:36 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2014-12-19 15:17:36 -07:00
|
|
|
}
|