Hardware Reference
In-Depth Information
7. Write the main game loop so that it waits for a button press, then sets off a
bomb. Remember that your button connects to 0 volts when it is pressed, which
is why you have to compare the GPIO against False here to detect a button
press.
try:
while True:
time.sleep(0.1)
if GPIO.input(BUTTON) == False:
pos = mc.player.getTilePos()
bomb(pos.x, pos.y, pos.z)
finally:
GPIO.cleanup()
Save your program and run it. Remember that on the Raspberry Pi, you have to use
sudo python detonator.py from within an LXTerminal window.
Run to somewhere in the Minecraft world and press your big red button—then run for
your life! Figure 5-17 shows the aftermath of the explosion—a massive crater.
FIGURE.5-17 A crater blown into the Minecraft world
Search WWH ::




Custom Search