grovetemp.cxx: Improve C++ example

Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Sarah Knepper 2014-12-04 10:58:38 +00:00 committed by Brendan Le Foll
parent 237f9cc36d
commit 39e6065046

View File

@ -1,5 +1,6 @@
/* /*
* Author: Brendan Le Foll <brendan.le.foll@intel.com> * Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 Intel Corporation. * Copyright (c) 2014 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
@ -24,18 +25,30 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <iomanip>
#include "grove.h" #include "grove.h"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
//! [Interesting] //! [Interesting]
upm::GroveTemp* s = new upm::GroveTemp(0);
std::cout << s->name() << std::endl; // Create the temperature sensor object using AIO pin 0
upm::GroveTemp* temp = new upm::GroveTemp(0);
std::cout << temp->name() << std::endl;
// Read the temperature ten times, printing both the Celsius and
// equivalent Fahrenheit temperature, waiting one second between readings
for (int i=0; i < 10; i++) { for (int i=0; i < 10; i++) {
std::cout << s->value() << std::endl; int celsius = temp->value();
int fahrenheit = (int) (celsius * 9.0/5.0 + 32.0);
printf("%d degrees Celsius, or %d degrees Fahrenheit\n",
celsius, fahrenheit);
sleep(1); sleep(1);
} }
// Delete the temperature sensor object
delete temp;
//! [Interesting] //! [Interesting]
return 0; return 0;