[{"id":2895,"name":"9.Tracking","moduletypeid":459,"content":"<p style=\"text-align: center;\"><br\/><\/p><p style=\"text-align: left; line-height: 1.75em;\"><strong><span style=\"font-family: Arial;color: rgb(255, 0, 0);letter-spacing: 0;font-size: 16px;background: rgb(255, 255, 255)\">! Note: This experiment must be done indoors to reduce the interference of sunlight on the infrared sensor.<\/span><\/strong><\/p><p style=\"text-align: left; line-height: 1.75em;\"><em><strong><span style=\"font-family: Arial;font-size: 16px\">Learning goal<\/span><span style=\"font-size: 16px;\"><span style=\"font-family:宋体\">:<\/span><\/span><\/strong><\/em><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\"font-family: Arial;font-size: 16px\">This lesson learns how to <\/span><span style=\"font-family: Arial;font-size: 16px\">use tracking sensor <\/span><span style=\"font-family: Arial;font-size: 16px\">by Python programming.<\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><em><strong><span style=\"font-family: Arial;font-size: 16px\">Code:<\/span><\/strong><\/em><\/p><p style=\"text-align: left; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20200909\/1599636129865885.png\" title=\"1599636129865885.png\" alt=\"image.png\" style=\"text-align: center;\"\/><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\"font-family: Arial;font-size: 16px;background: rgb(255, 255, 255)\">1)&nbsp;<\/span><span style=\"font-family: Arial;font-size: 16px;background: rgb(255, 255, 255)\">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.<\/span><\/p><p style=\"line-height: 1.75em;\">2)<span style=\"font-family:Arial;color:rgb(0,176,80);font-weight:bold;font-size:16px;background:rgb(255,255,255)\">&nbsp;<\/span><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px;background: rgb(255, 255, 255)\">display.show (Image.<\/span><\/strong><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px;background: rgb(255, 255, 255)\">NO<\/span><\/strong><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px;background: rgb(255, 255, 255)\">)<\/span><\/strong><span style=\"font-family: Arial;font-size: 16px;background: rgb(255, 255, 255)\">: Display a <\/span><span style=\"font-family: Arial;font-size: 16px;background: rgb(255, 255, 255)\">“X”<\/span><span style=\"font-family: Arial;font-size: 16px;background: rgb(255, 255, 255)\">&nbsp;on micro:bit dot matrix.<\/span><\/p><p style=\"line-height: 1.75em;\">3)<span style=\"font-family:Arial;color:rgb(0,176,80);font-weight:bold;font-size:16px\">&nbsp;<\/span><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px\">trakeL<\/span><\/strong><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px\">&nbsp;= tinybit.traking_sensor_L()<\/span><\/strong><span style=\"font-family: Arial;font-size: 16px\"><span style=\"font-family:宋体\">：<\/span>Read the data from the left <\/span><span style=\"font-family: Arial;font-size: 16px\">tracking<\/span><span style=\"font-family: Arial;font-size: 16px\">&nbsp;sensor, return <\/span><span style=\"font-family: Arial;font-size: 16px\">T<\/span><span style=\"font-family: Arial;font-size: 16px\">rue when a black line is detected, return <\/span><span style=\"font-family: Arial;font-size: 16px\">F<\/span><span style=\"font-family: Arial;font-size: 16px\">alse when a white line is detected, and save the read result to the<\/span><span style=\"font-family: Arial;font-size: 16px\">&nbsp;<\/span><span style=\"font-family: Arial;font-size: 16px\">variable<\/span><span style=\"font-family: Arial;font-size: 16px\">&nbsp;<\/span><span style=\"font-family: Arial;font-size: 16px\">trakeL<\/span><span style=\"font-family: Arial;font-size: 16px\">.<\/span><\/p><p style=\"line-height: 1.75em;\">4)<span style=\"font-family:Arial;color:rgb(0,176,80);font-weight:bold;font-size:16px\">&nbsp;<\/span><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px\">trakeR<\/span><\/strong><strong><span style=\"font-family: Arial;color: rgb(0, 176, 80);font-size: 16px\">&nbsp;= tinybit.traking_sensor_R()<\/span><\/strong><span style=\"font-family: Arial;font-size: 16px\"><span style=\"font-family:宋体\">：<\/span>Read the data from the <\/span><span style=\"font-family: Arial;font-size: 16px\">right tracking<\/span><span style=\"font-family: Arial;font-size: 16px\">&nbsp;sensor, return <\/span><span style=\"font-family: Arial;font-size: 16px\">T<\/span><span style=\"font-family: Arial;font-size: 16px\">rue when a black line is detected, return <\/span><span style=\"font-family: Arial;font-size: 16px\">F<\/span><span style=\"font-family: Arial;font-size: 16px\">alse when a white line is detected, and save the read result to the<\/span><span style=\"font-family: Arial;font-size: 16px\">&nbsp;<\/span><span style=\"font-family: Arial;font-size: 16px\">variable<\/span><span style=\"font-family: Arial;font-size: 16px\">&nbsp;<\/span><span style=\"font-family: Arial;font-size: 16px\">trakeR<\/span><span style=\"font-family: Arial;font-size: 16px\">.<\/span><\/p><p style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; text-indent: 0px; background: rgb(255, 255, 255); text-align: left; line-height: 1.75em;\"><span style=\"font-family: Arial;font-size: 16px\">5)&nbsp;<\/span><span style=\"font-family: Arial;font-size: 16px\">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.<\/span><\/p><p style=\"margin-top: 0px; margin-bottom: 0px; background: rgb(255, 255, 255); text-align: left; line-height: 1.75em;\"><em><strong><span style=\"font-family: Arial;letter-spacing: 0;font-size: 16px\">Programming and downloading<\/span><span style=\"letter-spacing: 0px; font-size: 16px;\"><span style=\"font-family:宋体\">:<\/span><\/span><\/strong><\/em><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\"font-family: Arial;font-size: 16px\">1.<\/span><span style=\"font-family: Arial;font-size: 16px\">You should open the Mu software, and enter the code in the edit window, , as shown below. <\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><strong><span style=\"font-family: Arial;font-size: 16px\">Note! All English and symbols should be entered in English, and the last line must be a space.<\/span><\/strong><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20200102\/1577938026114301.png\" title=\"1577938026114301.png\" alt=\"image.png\" width=\"613\" height=\"261\"\/><span style=\";font-family:Arial;font-size:16px\">&nbsp;<\/span><\/p><p style=\"margin-left: 0px; text-indent: 0px; text-align: left; line-height: 1.75em;\"><span style=\"font-family:Arial;font-size:16px\">2.<\/span><span style=\";font-family:Arial;font-size:16px\">You can click the <\/span><strong><span style=\"font-family: Arial;font-size: 16px\">“Check”<\/span><\/strong><span style=\";font-family:Arial;font-size:16px\">&nbsp;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.<\/span><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20200102\/1577938033719362.png\" title=\"1577938033719362.png\" alt=\"image.png\" width=\"625\" height=\"228\"\/><span style=\";font-family:Arial;font-size:16px\">&nbsp;<\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;font-size:16px\">3.Click <\/span><strong><span style=\"font-family: Arial;font-size: 16px\">“REPL”<\/span><\/strong><span style=\";font-family:Arial;font-size:16px\">&nbsp;button,check whether the tinybit library has been downloaded. If not, please refer to the [preparation before class]---&gt; [Python programming]<\/span><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20200102\/1577938039607135.png\" title=\"1577938039607135.png\" alt=\"image.png\"\/><span style=\";font-family:Arial;font-size:16px\">&nbsp;<\/span><\/p><p style=\"margin: 0px; text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;font-size:16px\">4.Click the <\/span><strong><span style=\"font-family: Arial;font-size: 16px\">“Flash”<\/span><\/strong><span style=\";font-family:Arial;font-size:16px\">&nbsp;button to download the program to micro:bit board.<\/span><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20200102\/1577938046389824.png\" title=\"1577938046389824.png\" alt=\"image.png\" width=\"612\" height=\"225\"\/><span style=\";font-family:Arial;font-size:16px\">&nbsp;<\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;color:rgb(112,48,160);font-size:16px\">If the program is wrong or the experimental phenomenon is wrong after downloading, please confirm whether you have downloaded the Buildingbit libraryhex&nbsp;file&nbsp;we&nbsp;provided to the micro: bit board.<\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;color:rgb(112,48,160);font-size:16px\">For the specific method of adding library files, please refer to&nbsp;<\/span><span style=\";font-family:Arial;color:rgb(112,48,160);font-size:16px\"><span style=\"font-family:宋体\">【<\/span><\/span><span style=\";font-family:Arial;color:rgb(112,48,160);letter-spacing:0;font-size:16px;background:rgb(255,255,255)\">1.Preparation before class<\/span><span style=\";font-family:Arial;color:rgb(112,48,160);letter-spacing:0;font-size:16px;background:rgb(255,255,255)\"><span style=\"font-family:宋体\">】<\/span><\/span><span style=\";font-family:Arial;color:rgb(112,48,160);letter-spacing:0;font-size:16px;background:rgb(255,255,255)\">---<\/span><span style=\";font-family:Arial;color:rgb(112,48,160);letter-spacing:0;font-size:16px;background:rgb(255,255,255)\"><span style=\"font-family:宋体\">【<\/span><\/span><span style=\";font-family:Arial;color:rgb(112,48,160);letter-spacing:0;font-size:16px;background:rgb(255,255,255)\">P<\/span><span style=\";font-family:Arial;color:rgb(112,48,160);font-size:16px\">ython programming<\/span><span style=\";font-family:Arial;color:rgb(112,48,160);font-size:16px\"><span style=\"font-family:宋体\">】<\/span><\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><em><strong><span style=\"font-family: Arial;font-size: 16px\">Experimental phenomena:<\/span><\/strong><\/em><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;font-size:16px\">After <\/span><span style=\";font-family:Arial;font-size:16px\">download is complete, open the power switch<\/span><span style=\";font-family:Arial;font-size:16px\">. <\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;font-size:16px\">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.<\/span><\/p><p style=\"text-align: left; line-height: 1.75em;\"><span style=\";font-family:Arial;font-size:16px\">When the black line is no detected, “X” is displayed.<\/span><\/p>","videotype":2,"videoname_1":"``http:\/\/www.yahboom.net\/xiazai\/Tiny_bit\/10.micro python course\/1.Basic course\/Tracking.py","videoname_2":"``","videoname_3":"``","videoname_4":"``","videoname_5":"``","videoname_6":"``","newimg":0,"dataurl":"","customurl":"","documentation_switch":"","classificationid":115,"paixu":10,"adddate":"1564044339"},[["","","http:\/\/www.yahboom.net\/xiazai\/Tiny_bit\/10.micro python course\/1.Basic course\/Tracking.py","Tracking.py"]]]