8. case 06 Turns over Detection

8.1. Our Goal


  • Make the car to stop when it turns over.

8.2. Requiered Materials


  • 1 x Ring:bit Car

8.3. Hardware Connect


  • Connect the left wheel servo to P1 of the Ring:bit expansion board and the right wheel servo to P2.(As below picture) ../../_images/MT6Y00d.png

8.4. Software


makecode

8.5. Coding


Step 1

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

../../_images/2qCyzQ7.png

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

../../_images/1Wq2Mov.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. Set Neopixel with 24 leds in RGB format for colorful light and show rainbow from 1 to 360. Then, initialize the P1 port to left wheel and the P2 port to right wheel.

../../_images/R1Fowaz.png

Step 3


  • Set a variable to state for controlling car’s running. Then set state variable unber the logo up block to true and the other to false. ../../_images/wjmku1o.png

Step 4


  • Set the rainblw led to colorful lights under the forever loop in gradual change. Use the variable state to control car’s running. ../../_images/zla50WK.png

Program

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

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

---

8.6. Result


  • The car runs normally,when it turns over, it stops.

../../_images/V9cw4sp.gif

8.7. Think


  • How can you design more funny project using other kits?

8.8. Questions


8.9. More Information