Adds mqtt example (#68)
[EVA-2020-02-2.git] / examples / light.py
1 #!/usr/bin/env python3
2
3 import time
4 import logging
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
12
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.
19
20 Press Ctrl+C to exit!
21
22 """)
23
24 try:
25 while True:
26 lux = ltr559.get_lux()
27 prox = ltr559.get_proximity()
28 logging.info("""Light: {:05.02f} Lux
29 Proximity: {:05.02f}
30 """.format(lux, prox))
31 time.sleep(1.0)
32 except KeyboardInterrupt:
33 pass