2014-12-02 16:45:40 -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-02 16:45:40 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-02 16:45:40 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-09-12 15:25:45 -07:00
|
|
|
#include "moisture.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-12-02 16:45:40 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2014-12-02 16:45:40 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2014-12-02 16:45:40 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2014-12-02 16:45:40 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate a Moisture sensor on analog pin A0
|
|
|
|
upm::Moisture moisture(0);
|
2014-12-02 16:45:40 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Values (approximate):
|
|
|
|
// 0-300, sensor in air or dry soil
|
|
|
|
// 300-600, sensor in humid soil
|
|
|
|
// 600+, sensor in wet soil or submerged in water.
|
|
|
|
// Read the value every second and print the corresponding moisture level
|
|
|
|
while (shouldRun) {
|
|
|
|
int val = moisture.value();
|
|
|
|
cout << "Moisture value: " << val << ", ";
|
|
|
|
if (val >= 0 && val < 300)
|
|
|
|
cout << "dry";
|
|
|
|
else if (val >= 300 && val < 600)
|
|
|
|
cout << "moist";
|
|
|
|
else
|
|
|
|
cout << "wet";
|
2014-12-02 16:45:40 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << endl;
|
2014-12-02 16:45:40 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(1);
|
2014-12-02 16:45:40 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2014-12-02 16:45:40 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting" << endl;
|
2014-12-02 16:45:40 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2014-12-02 16:45:40 -07:00
|
|
|
}
|