You can go and buy a Micro:bit project kit from here: http://cpc.farnell.com/bbc-micro-bit-kits
This project uses the Micro:bit serial connection with the Pi to randomly send 1 or 0 through the serial connection to tell the Pi based python script whether or not to lay an active TNT block or inactive TNT block. Thus it is called TNT roulette. :)
Picture of set up of Micro:bit plugged into the Pi
You will need to have a Raspberry Pi and Micro:bit for this to work. You will need to install MU on the Raspberry Pi to flash the micro python script. You will need to keep the Micro:bit plugged into the Pi usb port.
Here is the micro python script for the Micro:bit:
#Written by David Whale and Martin O’Hanlon edited by Chris Penn
from microbit import*
REFRESH = 500
BlockID = 46
ActiveValues = [0,1] # 0 = off
a, b = button_a.was_pressed(), button_b.was_pressed()
Active = random.choice(ActiveValues)
print(a, b, BlockID,Active)
Python code to go on the Raspberry Pi
N.b. This needs to be run in Python 2.7
Code written by Martin O'Hanlon in the following blog post:
I have added a few bits on top
from mcpi.minecraft import Minecraft
from time import sleep
from mcpi import block as block
PORT = "/dev/ttyACM0"
BAUD = 115200
s = serial.Serial(PORT)
s.baudrate = BAUD
s.parity = serial.PARITY_NONE
s.databits = serial.EIGHTBITS
s.stopbits = serial.STOPBITS_ONE
#read the first line and flush any bad data
#read a line from the microbit,
data = s.readline()
#split the microbit data into x, y, z, a, b
data_s = data.rstrip().split(" ")
a = True if data_s == "True" else False
b = True if data_s == "True" else False
BlockID = int(data_s)
Active = int(data_s)
mc = Minecraft.create()
playerPos = mc.player.getTilePos()
a,b,BlockID, Active = read_microbit_data()
if a == True:
pos = mc.player.getPos()
msg = "Button pressed = ",str(a),"+ Block ID = ",BlockID," + ", "Active=",Active
1. Having flashed your Micro:bit script and leaving your Micro:bit plugged into your Pi.
2. Open Minecraft, create a new world, ensure you can see the character like in the picture above, minimise the screen.
3. Run the Python code in 2.7 from above.
4. Press the A button on the Micro:bit, look at Minecraft and you should see a TNT block has been dropped. Whack it to see if it is active or not!