Tuesday, 25 April 2017
GPIO zero Minecraft "Whack on board Led's"
This code uses Minecraft to turn on the on board leds by whacking either a TNT block or Glass block. It uses GPIO zero.
To find out about Gpio zero go here:
1. In Minecraft lay a TNT block, glass block and grass block.
2. Open the below code in Python 3.
3. Run the code below
4. Whack the one of the blocks and you should see some action with one of the on board LED's.
TNT turns on the red light
Grass turns on the green light
Glass is random
#import minecraft libraries
import mcpi.minecraft as minecraft
import mcpi.block as block
#import gpio and time
from gpiozero import LED
from time import sleep
mc = minecraft.Minecraft.create()
mc.postToChat("Turn on your Pi lights with MCPI and GPIO zero")
red = LED(35)
green = LED(47)
for i in range(0,6):
light = random.choice(LightList)
if light == "R":
if light == "L":
evs = mc.events.pollBlockHits()
for e in evs:
pos = e.pos
b = mc.getBlock(pos.x,pos.y,pos.z)
if b == 46:#tnt
elif b == 2:#Grass
elif b == 20:#Glass