Browse Source

grovelight.cxx: improve example code

Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
Sarah Knepper 10 years ago
parent
commit
a1abab8909
1 changed files with 11 additions and 2 deletions
  1. 11
    2
      examples/grovelight.cxx

+ 11
- 2
examples/grovelight.cxx View File

@@ -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
@@ -29,11 +30,19 @@
29 30
 int
30 31
 main(int argc, char **argv)
31 32
 {
32
-    // This example uses AIO 0
33 33
 //! [Interesting]
34
+    // Create the light sensor object using AIO pin 0
34 35
     upm::GroveLight* light = new upm::GroveLight(0);
35
-    int lightValue = light->value();
36 36
 
37
+    // Read the input and print both the raw value and a rough lux value,
38
+    // waiting one second between readings
39
+    while( 1 ) {
40
+        std::cout << light->name() << " raw value is " << light->raw_value() <<
41
+            ", which is roughly " << light->value() << " lux" << std::endl;
42
+        sleep(1);
43
+    }
44
+
45
+    // Delete the light sensor object
37 46
     delete light;
38 47
 //! [Interesting]
39 48
     return 0;