Infrared Sensor

class compLib.IRSensor.IRSensor

Access the different IR Sensors of the robot

static read(sensor: int) → int

Read one infrared sensor

Parameters

sensor – Which sensor to read. Between 1 and 5

Raises

IndexError

Returns

Sensor value. 10 bit accuracy

Return type

int

static read_all()

Read all IR sensors at once. This is faster than read as it only uses one SPI call for all sensors!

Returns

Tuple of all current ir sensors

static set(sensor: int, on: bool)

Turn on / off a IR emitter

Parameters

sensor – Which sensor to read. Between 1 and 5

Raises

IndexError

Examples

Testing analog sensors

from compLib import IRSensor

while True:
   print ("left: {}  middle: {}  right: {}".format(IRSensor.read(1), IRSensor.read(3), IRSensor.read(5)))