|
@@ -1,5 +1,6 @@
|
1
|
1
|
/*
|
2
|
2
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
|
3
|
+ * Contributions: Sarah Knepper <sarah.knepper@intel.com>
|
3
|
4
|
* Copyright (c) 2014 Intel Corporation.
|
4
|
5
|
*
|
5
|
6
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
@@ -24,18 +25,30 @@
|
24
|
25
|
|
25
|
26
|
#include <unistd.h>
|
26
|
27
|
#include <iostream>
|
|
28
|
+#include <iomanip>
|
27
|
29
|
#include "grove.h"
|
28
|
30
|
|
29
|
31
|
int
|
30
|
32
|
main(int argc, char **argv)
|
31
|
33
|
{
|
32
|
34
|
//! [Interesting]
|
33
|
|
- upm::GroveTemp* s = new upm::GroveTemp(0);
|
34
|
|
- std::cout << s->name() << std::endl;
|
|
35
|
+
|
|
36
|
+ // Create the temperature sensor object using AIO pin 0
|
|
37
|
+ upm::GroveTemp* temp = new upm::GroveTemp(0);
|
|
38
|
+ std::cout << temp->name() << std::endl;
|
|
39
|
+
|
|
40
|
+ // Read the temperature ten times, printing both the Celsius and
|
|
41
|
+ // equivalent Fahrenheit temperature, waiting one second between readings
|
35
|
42
|
for (int i=0; i < 10; i++) {
|
36
|
|
- std::cout << s->value() << std::endl;
|
|
43
|
+ int celsius = temp->value();
|
|
44
|
+ int fahrenheit = (int) (celsius * 9.0/5.0 + 32.0);
|
|
45
|
+ printf("%d degrees Celsius, or %d degrees Fahrenheit\n",
|
|
46
|
+ celsius, fahrenheit);
|
37
|
47
|
sleep(1);
|
38
|
48
|
}
|
|
49
|
+
|
|
50
|
+ // Delete the temperature sensor object
|
|
51
|
+ delete temp;
|
39
|
52
|
//! [Interesting]
|
40
|
53
|
|
41
|
54
|
return 0;
|