BBC Micro:bit and Scratch – Interactive Steering Wheel & Driving Game

One of my class assignments this week is to use the BBC Micro:bit to interface with a Scratch program weā€™ve written. I thought that this was the perfect opportunity to use myĀ ThreadBoardĀ to create an embedded system! My inspiration for the scratch program comes from vintage handheld electronic games that my mother would get for me and my brother from the Goodwill or the corner store. I have many fond memories of those dusty LCDs, discolored plastic casings, and buttons that would mysteriously stick when pressed. I particularly remember the racing games that we would play (e.g. figure 2) where you could only shift between two lanes to dodge oncoming cars. In the spirit of revisiting my youth, Iā€™ve recreated this type of game in Scratch.

The Micro:bitā€™s accelerometer is used to control the steering of the car, and the two switches are used to control the carā€™s horn. Scratch is used to play the driving game, titled: BBC Micro Driver.

The project page can be found here:Ā https://scratch.mit.edu/projects/428740218/

If you have any questions, want to keep up with my work, or just toss around ideas, please do so on my Twitter: @4Eyes6Senses. Thanks!

The music in the video was provided byĀ Vincent Haney.

Step 1: Materials

ThreadBoard ā€“Ā Link

BBC Micro:bit ā€“Ā LinkĀ ā€“Ā Follow these instructions to connect your microcontroller to Scratch

4mm (Diameter) x 3mm (Height) magnets ā€“Ā Link

Foam sheets ā€“Ā Link

Stainless steel conductive thread ā€“Ā Link

A Scratch account ā€“Ā Link

Tape

Step 2: Adding Magnets to Your Micro:bit Pins

Now that you have the materials itā€™s time to add magnets to the five Micro:bit pins. The reason we are adding magnets to the pins is to (1) hold the Micro:bit securely to the magnet enriched ThreadBoard and to (2) allow for the easy connection between the pins and the conductive thread. Typically, to connect the Micro:bit with conductive thread you would need to sew and secure the thread around the open pins, and if you wanted to change your design youā€™d need to cut the thread attached to the Micro:bit and possibly resew your project. With the ThreadBoard you can simply drop your conductive thread on top of the magnets and they will keep the thread secure to the Micro:bit pins and the ThreadBoard.

ā€“ Isolate one disk magnet from the set. Make sure that you have identified which end of the magnet will attract or repel the other magnets, the poles of the five magnets need to be the same so that they are attracted to the magnets that will be embedded into the ThreadBoard.

ā€“ Gently push the magnet through the pin until it is secured. The magnet at this point should be crooked in the pin and will detach if placed on a metallic surface and pulled. Continue this process for the next four magnets.

ā€“ Using pliers or a flat surface, apply light pressure on the bottom of the magnets until they are secured in the pins and sit even. If at any point you want to remove the magnets, apply light pressure on the top and theyā€™ll pop out easily.

Step 3: Create the Controller

Once you have your materials, I suggest you start with wiring the two switches. The way the switches work is that you place a ground wire around the outer halo of the ThreadBoard, where your hands will hold the controller. Then, when your fingers touch the wires connected to the ThreadBoardā€™s ā€œ0ā€ or ā€œ2ā€ pins you will bridge the connection and cause the car to honk. Here are the steps:

ā€“ Place the conductive thread on the outermost ring of magnets and then place the thread on the ā€œGNDā€ pin of the Micro:bit (Figure 1).

ā€“ For the left button, place one end of the conductive thread on the ā€œ0ā€ pin of the Micro:bit. Create a trail to the left and place the end where you want the button. Grab your cut foam and thread it with the conductive thread (Figure 2), once you know where you want to place the button, secure the foam and thread with one of your extra magnets (Figure 3).

ā€“ For the right button, place a small piece of tape over the thread connected to ā€œGNDā€ (Figure 4) this will isolate the two wires and avoid causing a short. then follow the same steps as the left button.

Step 4: Create the Program

The link for the project can be found here:Ā https://scratch.mit.edu/projects/428740218/. The code is broken into three parts: the userā€™s car, car 1 (the blue car), and car 2 (the red car). Car 1 & 2ā€™s code is relatively the same, just with different x and y coordinates and a different ā€œwaitā€ function.

ā€“ Userā€™s car (Figure 1): When the user presses the green flag/start button their car will start at a predetermined position. when the user tilts the controller left or right the micro:bit will display the direction, and the program will move the userā€™s sprite to either the left or right side of the road. When the user presses the switch on the controller the car will make either a car horn or clown honk (depending on if they press the left or right button), this will also cause the carā€™s tail lights to turn on (switch costume). When the car crashes with another car (this is handled in the car 1 and car 2 code) the backdrop will switch to the game over screen and the userā€™s car will disappear.

Car 1 & car 2 (Figures 2 & 3): When the user presses the green flag/start button, the score is reset to 0 and the game over screen switched to the main highway scene. The ā€œrepeat untilā€ loop makes sure that cars are continuously generated as the user plays. The car is placed at the top and ā€œglidesā€ down the screen at a random interval ranging from 1 to 5 or 10 seconds (depending on the car). The if statement checks if thereā€™s a collision between the userā€™s car and car 1 or 2, if yes, then we switch the backdrop to the game over screen and end the game. if there isnā€™t a collision, then we add 1 to the userā€™s score and the car disappears off the bottom of the screen.

Source: BBC Micro:bit and Scratch ā€“ Interactive Steering Wheel & Driving Game


About The Author

Muhammad Bilal

I am a highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top