17. Case 14: Remote Control with Joystick:bit#

17.1. Purpose#


  • Programme to control the TPBot with the Joystick:bit.

17.2. Material#


../../_images/TPBot_tianpeng_case_01_01.png

17.3. Software#


MicroSoftmakecode

17.4. Programming#


  • Click “Advanced” to see more choices in the MakeCode drawer.

../../_images/TPBot_tianpeng_case_01_02.png

  • We need to add a package for programming. Click “Extensions” in the bottom of the drawer and search with “tpbot” in the dialogue box to download it.

../../_images/TPBot_tianpeng_case_01_03.png

  • We need to add a package for programming the Joystick also. Click “Extensions” in the bottom of the drawer and seach with “joystick” in the dialogue box to download it.

../../_images/TPBot_tianpeng_case_14_03.png

Sample#

Remote Control Part#

  • Set the radio group as 1.

  • Judge the value of x&y of the Joystick in the forever brick, if the value of the x is below 200, radio send number 4; if the value of the x is over 800, radio send number 3; if the value of the y is below 200, radio send number 2; if the value of the y over 800, radio send number 1; or radio send number 0.

../../_images/TPBot_tianpeng_case_14_04.png

Receiving Part#

  • Set the radio group as 1.

  • Save the received number as the variable in “on radio received…”block.

  • Judge if the value is 1, if yes, set the TPBot moving forward at the speed of 100%; if it’s 2, set the TPBot reversing at the speed of 50%; if it’s 3, set the TPBot turning left at the speed of 50%; if it’s 4, set the TPBot turning right at the speed of 50%; If it’s 0, set the TPBot to stop.

../../_images/TPBot_tianpeng_case_14_05.png

Link#

Conclusion#

  • The movement of the TPBot is controlled via the Joystick:bit.

17.5. Exploration#


17.6. FAQ#


Q: The car does not work with the code in the wiki.
A: It should be the batteries that are lack of power, please try to fix it by adding the value of the speed in the code.

17.7. Relevant File#