Pi Supply bit:buggy Project 07 – Turn over detection

What happens when your bit:buggy accidentally flips over? Well it keeps running. In this project we are going to detect when the bit:buggy flips and then switch off the motors.

Connect your hardware

If you haven’t done so already, connect the left servo wheel to P1 and the right servo wheel to P2.

Coding

Step 1 – Snap the on start block from the Basic. Set Neopixel with 24 LEDs in RGB format for colourful light and show rainbow from 1 to 360. Then, initialise the P1 port to left wheel and the P2 port to right wheel.

Step 2 – Set a variable to state for controlling car’s running. Then set state variable under the logo up block to true and the other to false.

Step 3 – Set the rainbow led to colourful lights under the forever loop in gradual change. Use the variable state to control car’s running.

Step 4 – Upload your program to the bit:buggy

Here is the program link – https://makecode.microbit.org/_D69AjDCi78UV

 Action

The car will run normally until it get flipped over where it will stop the motors.

Project Examples

 

First published at 10:33am on October 30, 2019
Last updated at 1:45pm on December 12, 2019