Hardware Reference
In-Depth Information
1. Start a new program by choosing File New File and save it as detonator.py .
2. Import the necessary modules:
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import anyio.seg7 as display
3. Configure the GPIO settings for your computer:
On the Raspberry Pi:
import RPi.GPIO as GPIO
BUTTON = 4
LED_PINS = [10,22,25,8,7,9,11,15] # order important
On the Arduino:
import anyio.GPIO as GPIO
BUTTON = 4
LED_PINS = [7,6,14,16,10,8,9,15] # order important
4. Setup the GPIO for the button so it is an input, and configure the display GPIOs.
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN)
ON = False # False=common-anode, True=common-cathode
display.setup(GPIO, LED_PINS, ON)
5. Connect to the Minecraft game.
mc = minecraft.Minecraft.create()
6. Write a function that drops a block of TNT to mark where the bomb will go of,
counts down to zero, then blows a big crater where the TNT block was. The fol-
lowing code builds the TNT block slightly to the side of the player so it doesn't
land on top of him! Note that the crater is 20 blocks in size (10 to the left and 10
to the right of your player) and this size is set by the calculations done in
setBlocks() here:
def bomb(x, y, z):
mc.setBlock(x+1, y, z+1, block.TNT.id)
for t in range(6):
display.write(str(5-t))
time.sleep(1)
mc.postToChat("BANG!")
mc.setBlocks(x-10, y-5, z-10, x+10, y+10, z+10,
block.AIR.id)
 
Search WWH ::




Custom Search