7. MOVEMotor line sensors

7.1. Use MOVEMotor library

To use the MOVEMotor module, import it via: import MOVEMotor.
from microbit import *
import MOVEMotor

7.2. Set up the line sensors

class MOVEMotorLineSensors
Set up the line sensors for use.
from microbit import *
import MOVEMotor


# setup line sensor
line_sensor = MOVEMotor.MOVEMotorLineSensors()

7.3. Calibrate the line sensors

The line sensors need to be calibrated while over a consistent surface, so that there is no major differences in the left and right sensor readings.
line_sensor_calibrate() will store relative differences in the line sensor reading during calibration and use these to make adjustments to any further readings.
line_sensor_calibrate()
Calibrates the line sensors to allow for any slight differences between them.
from microbit import *
import MOVEMotor


# setup line sensor
line_sensor = MOVEMotor.MOVEMotorLineSensors()

line_sensor.line_sensor_calibrate()

7.4. Read values from the line sensors

line_sensor_read(sensor)
Return the line sensor value.
Typical values over white are 150 to 200, while over black they are often around 50.
sensor is ‘left’ or ‘right’
from microbit import *
import MOVEMotor


# setup line sensor
line_sensor = MOVEMotor.MOVEMotorLineSensors()
line_sensor.line_sensor_calibrate()

left_reading = line_sensor.line_sensor_read('left')
display.scroll(left_reading)

Tasks

  1. Write code to read the right line sensor and display its value.

  2. Write code to read both the left and the right line sensor and display their values with ‘L’ before the left reading and ‘R’ before the right reading.