We are building lunch box buggies controlled by Microbits as part of a CAS project. So far, I’ve built two versions of the buggy (one in Lego and one using Kitronik kit) and quickly written some very simple code to make it move forward.
I wanted to have some basic sections of code that our children could tinker with and then put together in a sequence to navigate the buggy around a given course.
As I understand it, the motor board has four pins that between them can control 2 motors. There are two wires from one motor to the motor board that connect to two pins (i.e.: motor 1 uses PIN12 and PIN8 and motor 2 uses PIN16 and PIN0).
Using the command ‘digital write pin12 to 1’ turns the electricity on to pin12 (on motor 1) and ‘digital write pin12 to 0’ turns the electricity off to pin12. So going forward when both button A+B are pressed looks like this:
I’ve tried the buggy on a few different surfaces at home as the wheels seem to slip sometimes, and the shape of the lunchbox, with slightly sloping sides causes the wheels to be a slight angle. All of this can make the turns slightly more or less than the 90 degree turn I want, but this is something we can debug with code and with the mechanical aspects with the children once we have the final buggies made.
The code I’ve written so far is published online in the PXT editor. Button A turns right (clockwise), Button B turns left (anticlockwise) and A+B makes the buggy go forward.