Module IRRemoteSensor
[frames] | no frames]

Source Code for Module IRRemoteSensor

 1  # IRRemoteSensor.py 
 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   
19 -class IRRemoteSensor(GenericSensor):
20 - def __init__(self, port):
21 GenericSensor.__init__(self, port) 22 self.bp.set_sensor_type(self._getPort(), self.bp.SENSOR_TYPE.EV3_INFRARED_REMOTE) 23 time.sleep(4) # wait until setup is complete
24
25 - def getValue(self, channel):
26 ''' 27 Returns list of [red up, red down, blue up, blue down, boadcast] 0/1 values or None, if detection fails. 28 channel: 0, 1, 2, 4 determined by channel switch 29 ''' 30 if channel < 0 or channel > 3: 31 return None 32 try: 33 value = self.bp.get_sensor(self._getPort()) 34 except brickpi3.SensorError as error: 35 return None 36 Tools.debug("IRRemoteSensor.getValue() returned: " + str(value)) 37 return value[channel]
38