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