-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRGB.py
29 lines (25 loc) · 797 Bytes
/
RGB.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
import smbus
import time
bus = smbus.SMBus(1)
# I2C address 0x29
# Register 0x12 has device ver.
# Register addresses must be OR'ed with 0x80
bus.write_byte(0x29,0x80|0x12)
ver = bus.read_byte(0x29)
# version # should be 0x44
if ver == 0x44:
print "Device found\n"
bus.write_byte(0x29, 0x80|0x00) # 0x00 = ENABLE register
bus.write_byte(0x29, 0x01|0x02) # 0x01 = Power on, 0x02 RGB sensors enabled
bus.write_byte(0x29, 0x80|0x14) # Reading results start register 14, LSB then MSB
while True:
data = bus.read_i2c_block_data(0x29, 0)
clear = clear = data[1] | data[0]
red = data[3] | data[2]
green = data[5] | data[4]
blue = data[7] | data[6]
crgb = "C: %s, R: %s, G: %s, B: %s\r" % (clear, red, green, blue)
print crgb
time.sleep(1)
else:
print "Device not found\n"