3.11. Exercise: Line#
Navigate to the MicroPython editor https://python.microbit.org/v/3. If you already have it open, then use that existing window or tab.
Connect your micro:bit using the instructions on the previous page
Enter the following code into the editor
from microbit import *
def motor_left(speed, direction):
buf = bytearray(3)
buf[0] = 0x00
buf[1] = direction
buf[2] = speed
i2c.write(0x10, buf)
def motor_right(speed, direction):
buf = bytearray(3)
buf[0] = 0x02
buf[1] = direction
buf[2] = speed
i2c.write(0x10, buf)
i2c.init()
while True:
left_line = pin13.read_digital()
right_line = pin14.read_digital()
sleep(10)
Flash the code to your micro:bit.
If you get stuck ask a peer or your teacher for help!
Question 1
Extend the code so that:
the Maqueen follows the line
Solution
Solution is locked