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   
24   
26          if enable and not self._isActivateEnabled:   
27              self.bp.set_sensor_type(self._getPort(), self.bp.SENSOR_TYPE.NXT_LIGHT_ON) 
28              self._isActivateEnabled = True 
29          if not enable and self._isActivateEnabled: 
30              self.bp.set_sensor_type(self._getPort(), self.bp.SENSOR_TYPE.NXT_LIGHT_OFF) 
31              self._isActivateEnabled = False 
32          time.sleep(2)   
 33   
35          try: 
36              value = self.bp.get_sensor(self._getPort()) 
37          except brickpi3.SensorError as error: 
38             return 0 
39          print value 
40          value = max(0, 3200 - value) 
41          Tools.debug("NxtLightSensor.getValue() returned: " + str(value)) 
42          return value 
 43