chickenhouse/light_sensor.py

13 lines
287 B
Python
Raw Normal View History

2016-03-20 17:32:17 +00:00
import smbus
class light_sensor:
def __init__(self, bus = 1, addr = 0x23):
self.bus = bus
self.addr = addr
self.bus = smbus.SMBus(self.bus)
def read(self):
data = self.bus.read_i2c_block_data(self.addr, 0x10)
lx = int(round((data[0] * 256 + data[1]) / 1.2, 0))
return lx