light sensor class and test added
This commit is contained in:
parent
4d29363e27
commit
25f163b4cc
12
light_sensor.py
Normal file
12
light_sensor.py
Normal file
@ -0,0 +1,12 @@
|
||||
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
|
10
light_sensor_test.py
Executable file
10
light_sensor_test.py
Executable file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/python2
|
||||
|
||||
from light_sensor import light_sensor
|
||||
from time import sleep
|
||||
|
||||
ls = light_sensor(1, 0x23)
|
||||
|
||||
while True:
|
||||
print "light: " + str(ls.read()) + " lx."
|
||||
sleep(1)
|
Loading…
Reference in New Issue
Block a user