Merge pull request #62 from pimoroni/patch-noise-and-test-fixes
[EVA-2020-02-2.git] / examples / light.py
index 216477a766db19768e9d92683f7984bc664f3fac..db61e6a28d85b122d3cc391f0834ff700ea8e122 100755 (executable)
@@ -1,9 +1,21 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import time
 
 import time
-import ltr559
+import logging
+try:
+    # Transitional fix for breaking change in LTR559
+    from ltr559 import LTR559
+    ltr559 = LTR559()
+except ImportError:
+    import ltr559
+
+
+logging.basicConfig(
+    format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
+    level=logging.INFO,
+    datefmt='%Y-%m-%d %H:%M:%S')
 
 
-print("""light.py - Print readings from the LTR559 Light & Proximity sensor.
+logging.info("""light.py - Print readings from the LTR559 Light & Proximity sensor.
 
 Press Ctrl+C to exit!
 
 
 Press Ctrl+C to exit!
 
@@ -13,7 +25,7 @@ try:
     while True:
         lux = ltr559.get_lux()
         prox = ltr559.get_proximity()
     while True:
         lux = ltr559.get_lux()
         prox = ltr559.get_proximity()
-        print("""Light: {:05.02f} Lux
+        logging.info("""Light: {:05.02f} Lux
 Proximity: {:05.02f}
 """.format(lux, prox))
         time.sleep(1.0)
 Proximity: {:05.02f}
 """.format(lux, prox))
         time.sleep(1.0)