1   
 2   
 3  ''' 
 4   This software is part of the EV3BrickPi library. 
 5   It is Open Source Free Software, so you may 
 6   - run the code for any purpose 
 7   - study how the code works and adapt it to your needs 
 8   - integrate all or parts of the code in your own programs 
 9   - redistribute copies of the code 
10   - improve the code and release your improvements to the public 
11   However the use of the code is entirely your responsibility. 
12  ''' 
13   
14  from GenericSensor import GenericSensor 
15  import brickpi3 
16  import time 
17  from Tools import * 
18  from Color import Color 
19   
22          GenericSensor.__init__(self, port) 
23          self.bp.set_sensor_type(self._getPort(), self.bp.SENSOR_TYPE.EV3_COLOR_COLOR_COMPONENTS) 
24          time.sleep(2)   
 25   
27          ''' 
28          Returns list of [red light reflected, green light reflected, blue light reflected, unknown value]   
29          or None, if detection fails. 
30          ''' 
31          try: 
32              value = self.bp.get_sensor(self._getPort()) 
33          except brickpi3.SensorError as error: 
34             return None 
35          Tools.debug("ColorSensor.getValue() returned: " + str(value)) 
36          return value 
 37   
39          ''' 
40          Returns reference of the detected color or None, if detection fails. 
41          See class Color for more details. 
42          ''' 
43          value = self.getValue() 
44          if value != None:     
45              return Color(value[0:4]) 
46          else: 
47              return None 
 48