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