Merge pull request #72 from petermcd/example-fixes
[EVA-2020-02-2.git] / examples / light.py
CommitLineData
20442c9a 1#!/usr/bin/env python3
0cf10e5b
PH
2
3import time
10b73e18 4import logging
bca04496
PH
5try:
6 # Transitional fix for breaking change in LTR559
7 from ltr559 import LTR559
8 ltr559 = LTR559()
9except ImportError:
10 import ltr559
11
0cf10e5b 12
10b73e18
CM
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.
0cf10e5b
PH
19
20Press Ctrl+C to exit!
8ab4cd2d 21
0cf10e5b
PH
22""")
23
24try:
25 while True:
26 lux = ltr559.get_lux()
27 prox = ltr559.get_proximity()
10b73e18 28 logging.info("""Light: {:05.02f} Lux
0cf10e5b
PH
29Proximity: {:05.02f}
30""".format(lux, prox))
31 time.sleep(1.0)
32except KeyboardInterrupt:
33 pass