Welcome to Tiny:bit Pro repository
9.Tracking
! Note: This experiment must be done indoors to reduce the interference of sunlight on the infrared sensor.
Learning goal:
This lesson learns how to use tracking sensor by Python programming.
Code:

1) Import the library needed for this lesson from micro:bit, display is used for dot matrix display, Image calls the built-in image, pin12 is the pin of the body colorful lights, neopixel drives the body colorful lights, and tinybit controls the car.
2) display.show (Image.NO): Display a “X” on micro:bit dot matrix.
3) trakeL = tinybit.traking_sensor_L():Read the data from the left tracking sensor, return True when a black line is detected, return False when a white line is detected, and save the read result to the variable trakeL.
4) trakeR = tinybit.traking_sensor_R():Read the data from the right tracking sensor, return True when a black line is detected, return False when a white line is detected, and save the read result to the variable trakeR.
5) When trakeL and trakeR are True at the same time, that is, black lines are detected on both sides, a smiling face is displayed; if a black line is detected on the left, L is displayed; if a black line is detected on the right, R is displayed; When there is a black line, the character X is displayed.
Programming and downloading:
1.You should open the Mu software, and enter the code in the edit window, , as shown below.
Note! All English and symbols should be entered in English, and the last line must be a space.
2.You can click the “Check” button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.
3.Click “REPL” button,check whether the tinybit library has been downloaded. If not, please refer to the [preparation before class]---> [Python programming]
4.Click the “Flash” button to download the program to micro:bit board.
If the program is wrong or the experimental phenomenon is wrong after downloading, please confirm whether you have downloaded the Buildingbit libraryhex file we provided to the micro: bit board.
For the specific method of adding library files, please refer to 【1.Preparation before class】---【Python programming】
Experimental phenomena:
After download is complete, open the power switch.
When a black line is detected by the left line sensor, “L” is displayed on the LED dot matrix. When a black line is detected by the right sensor, “R” is displayed on the LED dot matrix. When a black line is detected on both sides at the same time, a smile is displayed.
When the black line is no detected, “X” is displayed.