Welcome to Tiny:bit Robot Car repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
8.Drive Motor
Learning goal:
This lesson learns how to drive motor by Python programming.
Code:
1) Import the libraries needed for this routine: display is used to display the dot matrix, Image is used to display the built-in pattern, sleep delay time, and tinybit is used to drive the car.
2) display.show (Image.HAPPY) Make the micro:bit display a smiling face.
3) tinybit.setMotorPWM (255, 255, 1000) Make both left and right motors forward.
The first parameter: the left motor speed, range is -255 ~ 255. A negative number indicates the motor reserve. A positive number indicates the motor forward, 0 means the motor stops.
The second parameter: the right motor speed, ranges is -255 ~255. A negative number indicates that the motor is reserve. A positive number indicates that the motor forward, 0 indicates that the motor is stop.
The third parameter: Delay time, the unit is milliseconds ms.
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. A smile face appears on the micro:bit dot matrix. Motor will forward 1s --> reserve 1s --> stop.