Micro:bit and Minecraft Clicker Racing game V1.0

This blog post is written by Chris Penn for the Virtual Pi Jam #PiParty

What you will need:

  • A Raspberry Pi with Minecraft Pi edition / Windows Laptop with Minecraft Java edition
  • Python 3
  • A Micro:bit
  • Read this blog on how to get started with David Whales BitIO library. (here)


This code uses the Micro:bit as an interactive controller in Minecraft. You can read all about it in BitIO blog 1 here to fully understand how to set it up and run it. But suffice to say that the Brains behind it is David Whale. Over the course of the the last 8 months I have been integrating the Micro:bit into my Minecraft coding experiments.

This is the latest… you will…………………..


  1. Build a strip of TNT blocks in Minecraft Pi / Java edition.
  2. Set a start position for the character in the world.
  3. Plug in the Micro:bit
  4. Open Idle / thonny / MU etc. Copy the code from below. Check for errors.
  5. Run the code and then click the ‘a’ button as many times as you can in a given time period I’ve set it to for 14 seconds for now.
  6. Race your mates, the ultimate winner is who can click the most in the time available. This will propel you along the TNT track and at the end reset your position.

Race your mates and celebrate the Raspberry Pi Birthday weekend on the 3-4 of March.

Once you have read all of the stuff above you can either download the completed code from the link below or follow the instructions above to complete the code, then run it. Good luck.

Example screenshots

Code (python)

#Written by Chris Penn 21/01/18 MB Transport. Adapted to Mini game 03/03/18 by Chris Penn

import time

import microbit

from mcpi.minecraft import Minecraft

import time

import random


mc = Minecraft.create()


LineColour = 46#block type of powered blocks



#initial research from here about timers



def procedure():




Start_Time = time.time()

Total_Time = 0.0

Button_Presses = 0


#set starting position

mc.player.setPos(-80,81,-248)# start position / reset race insert your own start coordinates here


while Total_Time <= 12.0:



if microbit.button_a.was_pressed():#while a button being pressed keep going fwd

Button_Presses = Button_Presses +1


Total_Time = time.time() – Start_Time

print(Total_Time,”Seconds lapsed”)

x,y,z = mc.player.getPos()

#get block -1

CurrentBlock = mc.getBlock(x,y-1,z)

#Go straight ahead

#if block -1 == 46 then

if CurrentBlock == 46 & mc.getBlock(x,y-1,z-1)== 46:#1ststraight


if CurrentBlock == 46 & mc.getBlock(x,y+1,z+1)== 46:#1ststraight



mc.player.setPos(-80,81,-248)#reset race insert your own start coordinates here

print(Button_Presses,” clicks in 12 seconds”)



Leave a Comment

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