Commit | Line | Data |
---|---|---|
0cf10e5b PH |
1 | #!/usr/bin/env python |
2 | ||
3 | import time | |
10b73e18 | 4 | import logging |
bca04496 PH |
5 | try: |
6 | # Transitional fix for breaking change in LTR559 | |
7 | from ltr559 import LTR559 | |
8 | ltr559 = LTR559() | |
9 | except ImportError: | |
10 | import ltr559 | |
11 | ||
0cf10e5b | 12 | |
10b73e18 CM |
13 | logging.basicConfig( |
14 | format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s', | |
15 | level=logging.INFO, | |
16 | datefmt='%Y-%m-%d %H:%M:%S') | |
17 | ||
18 | logging.info("""light.py - Print readings from the LTR559 Light & Proximity sensor. | |
0cf10e5b PH |
19 | |
20 | Press Ctrl+C to exit! | |
8ab4cd2d | 21 | |
0cf10e5b PH |
22 | """) |
23 | ||
24 | try: | |
25 | while True: | |
26 | lux = ltr559.get_lux() | |
27 | prox = ltr559.get_proximity() | |
10b73e18 | 28 | logging.info("""Light: {:05.02f} Lux |
0cf10e5b PH |
29 | Proximity: {:05.02f} |
30 | """.format(lux, prox)) | |
31 | time.sleep(1.0) | |
32 | except KeyboardInterrupt: | |
33 | pass |