def _update(self): if self._sensor_temp is not None: self.temperature = self._sensor_temp.readTempC() if self._sensor_tcs is not None: # Read the R, G, B, C color data. self.r, self.g, self.b, self.c = self._sensor_tcs.get_raw_data() # Calculate color temperature using utility functions. self.color_temp = Adafruit_TCS34725.calculate_color_temperature( self.r, self.g, self.b) # Calculate lux with another utility function. self.lux = Adafruit_TCS34725.calculate_lux(self.r, self.g, self.b) if self._touch_sensor is None: return touch_data = self._touch_sensor.touched() touched = False for i in range(12): pin_bit = 1 << i # Only transitions from not touched to touched are valid. if touch_data & pin_bit and not self._last_touched_data & pin_bit: touched = True break self._last_touched_data = touch_data list_len = len(self.touched_list) # Start storing touch events on initial touch. if touched and list_len == 0: self.touched_list.append(touched) self._collect_touches = True # Fill events until list is full. elif self._collect_touches and list_len < 20: self.touched_list.append(touched)
def readTCSAll(): avgr = 0 avgg = 0 avgb = 0 avgc = 0 count = 0 while (count < 130): tcs = Adafruit_TCS34725.TCS34725() r, g, b, c = tcs.get_raw_data() avgr = avgr + r avgg = avgg + g avgb = avgb + b avgc = avgc + c count = count + 1 tcs.disable() avgr = avgr / 130 avgg = avgg / 130 avgb = avgb / 130 avgc = avgc / 130 r = float(avgr) g = float(avgg) b = float(avgb) c = float(avgc) lux = float(Adafruit_TCS34725.calculate_lux(r, g, b)) color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) if color_temp is None: color_temp = 0 color_temp = float(color_temp) return r, g, b, c, lux, color_temp
def get_lux(self): # Read R, G, B, C color data from the sensor. r, g, b, c = self.tcs.get_raw_data() # Calulate color temp temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) #Calculate lux and multiply it with gain lux = Adafruit_TCS34725.calculate_lux(r, g, b) real_lux = lux # Calculate lux out of RGB measurements. print("temp [k]= ", temp) print("r :", r) print("g :", g) print("b :", b) print("c :", c) print("lux = ", lux) print("real_lux: ", real_lux) # Publish to topic # TODO: add other things to header self.msg_light_sensor.header.stamp = rospy.Time.now() self.msg_light_sensor.header.frame_id = rospy.get_namespace()[ 1:-1] # splicing to remove / self.msg_light_sensor.real_lux = real_lux self.msg_light_sensor.lux = lux self.msg_light_sensor.temp = temp self.sensor_pub.publish(self.msg_light_sensor) return lux
def Capture(integrationtime=2.4, gain=1, output='all'): # Capture function for RGB sensor try: # Dictionary for possible integration time values: dict = {} # creates a variable dictionary, for information about dictionaries: https://www.programiz.com/python-programming/dictionary # Add all integration time values to dictionary dict[2.4] = Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_2_4MS # (2.4ms, default) dict[24] = Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_24MS dict[50] = Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_50MS dict[101] = Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_101MS dict[154] = Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_154MS dict[700] = Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_700MS # Add possible gain values to Dictionary: dict[1] = Adafruit_TCS34725.TCS34725_GAIN_1X dict[4] = Adafruit_TCS34725.TCS34725_GAIN_4X dict[16] = Adafruit_TCS34725.TCS34725_GAIN_16X dict[60] = Adafruit_TCS34725.TCS34725_GAIN_60X # Create a TCS34725 instance with default integration time (2.4ms) and gain (4x). #tcs = Adafruit_TCS34725.TCS34725() # You can also override the I2C device address and/or bus with parameters: #tcs = Adafruit_TCS34725.TCS34725(address=0x30, busnum=2) # Or you can change the integration time and/or gain: tcs = Adafruit_TCS34725.TCS34725(integration_time=dict[integrationtime], gain=dict[gain]) # Disable interrupts (can enable them by passing true, see the set_interrupt_limits function too). tcs.set_interrupt(False) # Read the R, G, B, C color data. r, g, b, c = tcs.get_raw_data() # Calculate color temperature using utility functions. You might also want to # check out the colormath library for much more complete/accurate color functions. color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) # Calculate lux with another utility function. lux = Adafruit_TCS34725.calculate_lux(r, g, b) if color_temp is None: raise AttributeError('Too dark to determine color temperature!') tcs.set_interrupt(True) tcs.disable() # Determines outputs depending on function parameters: if output == 'all': return r, g, b, c, lux, color_temp elif output == 'rgbc': return r, g, b, c elif output == 'lux': return lux elif output == 'temp': return color_temp except KeyError: raise ValueError('No such integration time or gain, refer to coliform-project guide in github for possible options.')
def color(self): self.r, self.g, self.b, self.c = self.sensor_tcs.get_raw_data( ) # Read the R, G, B, C color data. self.color_temp = Adafruit_TCS34725.calculate_color_temperature( self.r, self.g, self.b) # Calculate color temperature using utility functions. self.lux = Adafruit_TCS34725.calculate_lux( self.r, self.g, self.b) # Calculate lux with another utility function.
def get_lux(self): # Read R, G, B, C color data from the sensor. r, g, b, c = self.tcs.get_raw_data() # Calulate color temp temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) # Calculate lux and multiply it with gain self.lux = Adafruit_TCS34725.calculate_lux(r, g, b) # Calculate lux out of RGB measurements. print("temp [k]= ", temp) print("r :", r) print("g :", g) print("b :", b) print("c :", c) print("lux = ", self.lux)
def get_data(self): # tcs = Adafruit_TCS34725.TCS34725() tcs = Adafruit_TCS34725.TCS34725( address=0x29, integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_2_4MS) tcs.set_interrupt(False) r, g, b, c = tcs.get_raw_data() color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) lux = Adafruit_TCS34725.calculate_lux(r, g, b) tcs.set_interrupt(True) tcs.disable() return lux
def talker(): #pub = rospy.Publisher('chatter', String, queue_size=10) publight = rospy.Publisher('lux', Float32, queue_size=10) pubr = rospy.Publisher('red', Float32, queue_size=10) pubg = rospy.Publisher('green', Float32, queue_size=10) pubb = rospy.Publisher('blue', Float32, queue_size=10) rospy.init_node('talker_light', anonymous=True) rate = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): # Read the R, G, B, C color data. r, g, b, c = tcs.get_raw_data() pubr.publish(r) pubg.publish(g) pubb.publish(b) # Calculate lux with utility function. lux = Adafruit_TCS34725.calculate_lux(r, g, b) # Print out the lux. #print('Luminosity: {0} lux'.format(lux)) publight.publish(lux) #hello_str = "hello world %s" % rospy.get_time() #rospy.loginfo(hello_str) #pub.publish(hello_str) rate.sleep()
def CheckColor(): tcs = Adafruit_TCS34725.TCS34725() tcs.set_interrupt(False) r, g, b, c = tcs.get_raw_data() color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) lux = Adafruit_TCS34725.calculate_lux(r, g, b) if color_temp is None: color_temp = 0 tcs.set_interrupt(True) tcs.disable() return r, g, b, c, lux, color_temp
def __init__(self): self.directionFacing = 'north' self.maxSpeed = 100 self.aStar = AStar() self.tcs = Adafruit_TCS34725.TCS34725() self.initialLeftCount = self.aStar.read_encoders()[0] self.initialRightCount = self.aStar.read_encoders()[1]
def __init__(self, ip): self.ip = ip self.scale = nt.getTable('Scale') self.switch = nt.getTable('Switch') self.sensor = af.TCS34725() self.sensor.set_interrupt(False)
def read_sensor(self): # Read the R, G, B, C color data. r, g, b, c = self._tcs.get_raw_data() # Calculate color temperature using utility functions. You might also want to # check out the colormath library for much more complete/accurate color functions. color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) # Calculate lux with another utility function. lux = Adafruit_TCS34725.calculate_lux(r, g, b) # Print out the values. print( 'Color: red={0} green={1} blue={2} clear={3}, Temperature: {4} K, Luminosity: {0} lux' .format(r, g, b, c, color_temp, lux))
def __init__(self, int_time_opt='50', gain_opt='4', led_ctrl_pin=26, led_on=True): # get the library constants for the gain and integration time from the option strings self._int_time = get_tcs_int_time(int_time_opt) self._gain = get_tcs_gain(gain_opt) print 'Initializing TCS with integration time: %sms, gain: %sX' % ( int_time_opt, gain_opt) print 'TCS LED control pin: %s, Initial State: %s' % (led_ctrl_pin, led_on) # You can also override the I2C device address and/or bus with parameters: #self._tcs = Adafruit_TCS34725.TCS34725(integration_time, gain, address=0x30, busnum=2) self._tcs = Adafruit_TCS34725.TCS34725(integration_time=self._int_time, gain=self._gain) # Disable interrupts (can enable them by passing true, see the set_interrupt_limits function too). self._tcs.set_interrupt(False) # set up the GPIO pin to control the LED on the TCS module and turn the LED on if specified GPIO.setmode(GPIO.BCM) self._led_ctrl_pin = led_ctrl_pin if led_on: initial_state = GPIO.HIGH else: initial_state = GPIO.LOW GPIO.setup(self._led_ctrl_pin, GPIO.OUT, initial=initial_state)
def __init__(self): #Get node name and vehicle name self.node_name = rospy.get_name() self.veh_name = self.node_name.split("/")[1] ##GPIO setup #Choose BCM or BOARD numbering schemes GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) #turn off LED GPIO.output(18, GPIO.LOW) #Set integrationtime and gain self.tcs = Adafruit_TCS34725.TCS34725( \ integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_700MS, \ gain=Adafruit_TCS34725.TCS34725_GAIN_1X) #Set parameter self.readParamFromFile() #Set local gain using yam self.mult = self.setup_parameter("~mult", 1) self.offset = self.setup_parameter("~offset", 1) #ROS-Publications self.msg_light_sensor = LightSensorM() self.sensor_pub = rospy.Publisher('~sensor_data', LightSensorM, queue_size=1) rate = rospy.Rate(10) while not rospy.is_shutdown(): self.get_lux() rate.sleep()
def run(self): tcs = Adafruit_TCS34725.TCS34725() tcs.set_interrupt(False) while True: r, g, b, c = tcs.get_raw_data() rgb_sensor.red = r rgb_sensor.blue = b rgb_sensor.green = g
def __init__(self): self.isLost = False self.nextSearchDirection = 0 # (left: 0, right: 1) self.veerSpeed = 30 self.maxSpeed = 70 self.aStar = AStar() self.tcs = Adafruit_TCS34725.TCS34725() self.initialLeftCount = self.aStar.read_encoders()[0] self.initialRightCount = self.aStar.read_encoders()[1]
def read_color(): sensor = Adafruit_TCS34725.TCS34725() sensor.set_interrupt(False) red, green, blue, clear = sensor.get_raw_data() sensor.set_interrupt(True) sensor.disable() print('RGBC read by sensor: {0}_{1}_{2}_{3}'.format( red, green, blue, clear)) return '{0}_{1}_{2}_{3}'.format(red, green, blue, clear)
def __init__(self): #Get node name and vehicle name self.node_name = rospy.get_name() self.veh_name = self.node_name.split("/")[1] ##GPIO setup #Choose BCM or BOARD numbering schemes GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) #turn off LED GPIO.output(18, GPIO.LOW) #Set integrationtime and gain self.tcs = Adafruit_TCS34725.TCS34725( \ integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_700MS, \ gain=Adafruit_TCS34725.TCS34725_GAIN_1X) # #Set parameter # self.readParamFromFile() # #Set local gain using yaml # self.mult = self.setup_parameter("~mult",1) # self.offset = self.setup_parameter("~offset", 1) #ROS-Publications self.msg_light_sensor = LightSensorM() self.sensor_pub = rospy.Publisher('~sensor_data', LightSensorM, queue_size=1) rate = rospy.Rate(10) self.lux1 = [] self.lux2 = [] input("Are you ready for the first light evaluation (ENTER)?") for count in range(53): if count > 3: self.lux1.append(self.get_lux()) rate.sleep() val1 = int(input("How much was the light luminescence?")) input("Are you ready for the next light evaluation (ENTER)?") for count in range(53): if count > 3: self.lux2.append(self.get_lux()) rate.sleep() val2 = int(input("How much was the light luminescence?")) std1 = np.std(self.lux1) med1 = np.median(self.lux1) std2 = np.std(self.lux2) med2 = np.median(self.lux2) #make sure that the standard deviation is not to big self.mult = (val2 - val1) / (med2 - med1) self.offset = val1 - self.mult * med1 self.set_param() return
def main(): kruispuntnr = 1 einde = False # True waarde nog te implementeren GPIO.setmode(GPIO.BOARD) # SPI-object maken voor afstandssensor CE = 0 # Eerste kanaal op ADC selecteren spi = spidev.SpiDev0(0, CE) spi.max_speed_hz = 1000000 kanaal = 0 # Eerste analoge signaal # Kleurensensor initialiseren i2c = busio.I2C(5, 3) kleurensensor = Adafruit_TCS34725.TCS34725(i2c) # Server initialiseren server = Server.Server() last_error = 0 # Nodig voor de eerst keer volglijn uit te voeren while not einde: while True: # Manuele override message = server.listen() if message: last_error = 0 break # Volg de lijn 10 keer for i in range(10): returnwaarde = lijninterpretatie() if returnwaarde == "stopstreep": stopMotor() kruispunt(kruispuntnr, kleurensensor, kanaal) kruispuntnr += 1 last_error = 0 #Herinitialisatie van lijnvolgalgoritme else: volglijn(returnwaarde) # Na 10 maal lijn te volgen, check de sensoren if adc.getAfstand(kanaal) < 15: stopMotor() while adc.getAfstand(kanaal) < 20: pass #Bericht uitlezen while message != 'Ga door': if message == 'rechtdoor': forward(10) time.sleep(0.0000001) stopMotor() message = server.listen() elif message == 'links': pass message = server.listen() raise Exception("Fout in de code.")
def get_color(self, mode="RGB"): try: self.r, self.g, self.b, self.c = self.sensor_tcs.get_raw_data( ) # Read the R, G, B, C color data. self.color_temp = Adafruit_TCS34725.calculate_color_temperature( self.r, self.g, self.b) # Calculate color temperature using utility functions. self.lux = Adafruit_TCS34725.calculate_lux( self.r, self.g, self.b) # Calculate lux with another utility function. except: self.r, self.g, self.b, self.c = [-1, -1, -1, -1] self.color_temp = -1 self.lux = -1 finally: if mode == "RGB": return (self.r, self.g, self.b) if mode == "hex": return '#%02x%02x%02x' % (self.r, self.g, self.b) if mode == "temp": return self.color_temp if mode == "lux": return self.lux
def __init__(self, mux, muxnum, servo, servonum, lednum): self.mux = mux self.muxnum = muxnum self.servo = servo self.servonum = servonum self.mux.channel(self.muxnum) self.sensor = Adafruit_TCS34725.TCS34725(address=0x29, busnum=1) self.lednum = lednum GPIO.setup(lednum, GPIO.OUT)
def get_lux(self): # Read R, G, B, C color data from the sensor. r, g, b, c = self.tcs.get_raw_data() # Calulate color temp temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) # Calculate lux and multiply it with gain lux = Adafruit_TCS34725.calculate_lux(r, g, b) real_lux = self.mult * lux + self.offset # Publish to topic #header self.msg_light_sensor.header.stamp = rospy.Time.now() self.msg_light_sensor.header.frame_id = rospy.get_namespace()[1:-1] self.msg_light_sensor.r = r self.msg_light_sensor.g = g self.msg_light_sensor.b = b self.msg_light_sensor.c = c self.msg_light_sensor.real_lux = real_lux self.msg_light_sensor.lux = lux self.msg_light_sensor.temp = temp self.sensor_pub.publish(self.msg_light_sensor)
def read_left_color(): GPIO.output("P8_7", GPIO.HIGH) sleep(0.1) tcs = Adafruit_TCS34725.TCS34725() r, g, b, c = tcs.get_raw_data() for i in range(0, 5): r_, g_, b_, c_ = tcs.get_raw_data() r += r_ g += g_ b += b_ c += c_ GPIO.output("P8_7", GPIO.LOW) print("Left: ", r / 5, g / 5, b / 5) return r / 5, g / 5, b / 5, c / 5
class TestSensor(unittest.TestCase): a_star = AStar() tcs = Adafruit_TCS34725.TCS34725() tcs.set_interrupt(False) turnWheelSpeed=70 def testSensorColor(self): self.assertTrue(getSensorColor(self.tcs)=='red' or getSensorColor(self.tcs)=='green' or getSensorColor(self.tcs)=='blue') def testRecalibrateLeft(self): calibrateLeft(self.a_star, self.tcs, 1000, self.turnWheelSpeed) self.assertTrue(checkIfGreen(self.tcs)) def testRecalibrateRight(self): calibrateRight(self.a_star, self.tcs, 1000, self.turnWheelSpeed) self.assertTrue(checkIfGreen(self.tcs))
def __init__(self, node_name, disable_signals=False): # initialize the DTROS parent class super(LightSensorCalibrator, self).__init__(node_name=node_name) self.veh_name = rospy.get_namespace().strip("/") # GPIO setup # Choose BCM or BOARD numbering schemes GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.LOW) # Set integrationtime and gain self.tcs = Adafruit_TCS34725.TCS34725( integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_700MS, gain=Adafruit_TCS34725.TCS34725_GAIN_1X) self.rate = rospy.Rate(10) #paths self.dirname = '/data/config/calibrations/light-sensor/' self.filename = self.dirname + self.veh_name + ".yaml" # look if we have already done a callibration if os.path.isdir(self.dirname): decission = input( "calibration is already done. Do you want to make a newcallibration ? [Y/N]" ) if (decission == "Y") or ( decission == "y"): # versuche wie or wirklich aussehen muss. shutil.rmtree(self.dirname) else: print( "the old calibration is still valid and the node will shutdown because we already have a callibration file" ) #make the folder for saving the callibration # if decission was not y or Y we will get now an error and process shutdown #vaiables self.mult = 1 self.offset = 0 self.lux = 0 if not os.path.isdir(self.dirname): #callibration self.callibrator() #set the parameter self.set_param()
def init(self): #Hardware configuration: try: # Create a TCS34725 instance self.tcs = TCS34725.TCS34725(address=self.I2CAddr, busnum=self.busnum, integration_time=self.IntT, gain=self.gain) except Exception as e: print("TCS34725Config: Error initialising device - exit") print(str(e)) sys.exit(1) # Disable interrupts (can enable them by passing true, see the set_interrupt_limits function too). self.tcs.set_interrupt(False)
def vrpnDataObserver(vrpnData): xpos = vrpnData.pose.position.x ypos = vrpnData.pose.position.y # Read the R, G, B, C color data. r, g, b, c = tcs.get_raw_data() #r = 0 #g = 0 #b = 0 #c = 0 #color_temp = 0 #lux = 0 # Calculate color temperature using utility functions. You might also want to # check out the colormath library for much more complete/accurate color functions. color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) # Calculate lux with another utility function. lux = Adafruit_TCS34725.calculate_lux(r, g, b) # Print out the values. print('Color: red={0} green={1} blue={2} clear={3}'.format(r, g, b, c)) # Print out color temperature. if color_temp is None: print('Too dark to determine color temperature!') color_temp = -1 else: print('Color Temperature: {0} K'.format(color_temp)) # Print out the lux. print('Luminosity: {0} lux'.format(lux)) f.write("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n" % (r, g, b, c, color_temp, lux, xpos, ypos))
def __init__(self): self.STEPS_PER_REV = 3200 self.DISTANCE_PER_REV = 0.2827433388 self.LUX_CUTOFF = 250 #completely random self.FLAME_LED = 18 self.START_LED = 23 self.ROTATION_KEY = 0.09 self.bno = BNO055.BNO055() if not self.bno.begin(): raise RuntimeError('Uh oh spaghetti-o\'s my bno055 is on the fritz') self.tcs = Adafruit_TCS34725.TCS34725() self.tcs.set_interrupt(False) GPIO.setmode(GPIO.BCM) self.setupLeds() self.SERIAL_PORT = serial.Serial('/dev/ttyUSB0', 9600, timeout=0)
def __init__(self, node_name): # initialize the DTROS parent class super(LightSensorNode, self).__init__(node_name=node_name) # Add the node parameters to the parameters dictionary and load their default values self.parameters['~default_mult'] = None self.parameters['~default_offset']=None self.parameters['~frequency']=None self.updateParameters() self.veh_name = rospy.get_namespace().strip("/") # GPIO setup # Choose BCM or BOARD numbering schemes GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.LOW) # Set integrationtime and gain self.tcs = Adafruit_TCS34725.TCS34725( integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_700MS, gain=Adafruit_TCS34725.TCS34725_GAIN_1X) #define file path self.filepath = '/data/config/calibrations/light-sensor/' + self.veh_name + ".yaml" #define parameter self.mult = 0 self.offset = 0 self.default_mult=self.parameters['~default_mult'] #default value = 1 self.default_offset= self.parameters['~default_offset'] #default value = 0 #set parametervalue self.readParamFromFile() #define time between evaluations in sec. self.timesensor = 1/self.parameters['~frequency'] #value = 1: every second one measurment # ROS-Publications self.msg_light_sensor = LightSensor() self.sensor_pub = self.publisher('~sensor_data', LightSensor, queue_size=1) while not rospy.is_shutdown(): self.get_lux() rospy.sleep(rospy.Duration.from_sec(self.timesensor))
def __init__(self): # Temp Sensor. self._sensor_temp = MCP9808.MCP9808() try: self._sensor_temp.begin() logging.info('Temperature sensor started.') except Exception as err: self._sensor_temp = None msg = 'An error occured while setting up temperature sensor: {}' logging.error(msg.format(str(err))) # Color Sensor. self._sensor_tcs = None try: self._sensor_tcs = Adafruit_TCS34725.TCS34725() self._sensor_tcs.set_interrupt(True) logging.info('Color sensor started.') except Exception as err: msg = 'An error occured while setting up color sensor: {}' logging.error(msg.format(str(err))) self._touch_sensor = MPR121.MPR121() try: self._touch_sensor.begin() logging.info('Touch sensor started.') except Exception as err: self._touch_sensor = None msg = 'An error occured while setting up touch sensor: {}' logging.error(msg.format(str(err))) self.temperature = 0 self.r, self.g, self.b, self.c = [0, 0, 0, 0] self.color_temp = 0 self.lux = 0 self.touched_list = [] self._last_touched_data = 0 self._collect_touches = False self.sensor_read_loop = tornado.ioloop.PeriodicCallback( self._update, 1000) self.sensor_read_loop.start()
# - TCS34725_INTEGRATIONTIME_700MS # Possible gain values: # - TCS34725_GAIN_1X # - TCS34725_GAIN_4X # - TCS34725_GAIN_16X # - TCS34725_GAIN_60X # Disable interrupts (can enable them by passing true, see the set_interrupt_limits function too). tcs.set_interrupt(False) # Read the R, G, B, C color data. r, g, b, c = tcs.get_raw_data() # Calculate color temperature using utility functions. You might also want to # check out the colormath library for much more complete/accurate color functions. color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) # Calculate lux with another utility function. lux = Adafruit_TCS34725.calculate_lux(r, g, b) # Print out the values. print('Color: red={0} green={1} blue={2} clear={3}'.format(r, g, b, c)) # Print out color temperature. if color_temp is None: print('Too dark to determine color temperature!') else: print('Color Temperature: {0} K'.format(color_temp)) # Print out the lux. print('Luminosity: {0} lux'.format(lux))