-
Notifications
You must be signed in to change notification settings - Fork 1
/
light2dac.py
41 lines (31 loc) · 1009 Bytes
/
light2dac.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import time,sys
sys.path.append('/home/pi/cloned/Adafruit-Raspberry-Pi-Python-Code/Adafruit_MCP4725')
import TSL2561b
from Adafruit_MCP4725 import MCP4725
# 12-bit
dacmax=2**12
minbrightness=0
maxbrightness=5.0
# 90 lux is dim daylight
# 3000 lux is flashlight shining on sensor
maxlux=1000.
class light2dac():
def __init__(self):
self.LightSensor = TSL2561b.Adafruit_TSL2561()
self.LightSensor.enableAutoGain(True)
# Initialise the DAC using the default address
self.dac = MCP4725(0x62)
def __call__(self):
self.lux=self.LightSensor.calculateLux()
self.brightness=maxbrightness*float(self.lux/1000.)
self.brightness=min(self.brightness, maxbrightness)
self.brightness=max(self.brightness, minbrightness)
self.dacvalue=int((self.brightness/maxbrightness)*dacmax)
self.dac.setVoltage(self.dacvalue)
#l=light2dac()
#
#while True:
#
# l()
# print l.lux,l.brightness,l.dacvalue
# time.sleep(1)