18. case 08 Light Follow#

18.1. Our Goal#

  • Make the ring:bit car to light follow.

18.2. Requiered Materials#

18.3. Hardware Connect#

  • Connect the left wheel servo to P1 of the Ring:bit expansion board and the right wheel servo to P2.

../../_images/jBVHea8.png

18.4. Software#

makecode

18.5. Coding#

Step 1#

  • Click on “Advanced” in the MakeCode Drawer to see more code sections.

../../_images/2qCyzQ71.png

  • Search for “ringbitcar” and click on the ring:bit car package to add it to your project. (As below picture)

../../_images/1Wq2Mov1.jpg

Note: If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Project file menu.

Step 2#

  • Snap the on start block from the Basic and initialize the P1 port to left wheel and the P2 port to right wheel.

../../_images/RFccHpJ1.png

Step 3#

  • Snap the light level from the Input. The car will move to the light source when the light level is greater than the defined value.

  • The car will spin around to find the light source when the light level is less than the defined value.

../../_images/i1lAR3X1.png

Program#

Program Link:https://makecode.microbit.org/_H7c7DPWTPYKY

If you don’t want to type these code by yourself, you can directly download the whole program from the link below:

18.6. Result#

  • The car spins around and will move to the light source when it is detecting the light.

../../_images/ENMYgJm.gif

18.7. Think#

  • How can you make a smart car to detect the fire?

18.8. Questions#

18.9. More Information#