Created
August 18, 2013 03:19
-
-
Save gelicia/6259737 to your computer and use it in GitHub Desktop.
Minecraft Pi / Pi Matrix LED Location display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smbus | |
import mcpi.minecraft as minecraft | |
import sched | |
import time | |
#chip definitions for the pi matrix and initialization of the bus to write to it | |
ADDR = 0x20 | |
DIRA = 0x00 | |
DIRB = 0x01 | |
PORTA = 0x12 | |
PORTB = 0x13 | |
bus = smbus.SMBus(1) | |
#sets a single LED and clears all others | |
def SetLED (row, col): | |
bus.write_byte_data(ADDR, PORTA, 0x80>>col)x | |
bus.write_byte_data(ADDR, PORTB, ~(1<<row)) | |
#intitialize ports | |
bus.write_byte_data(ADDR, DIRA, 0x00) | |
bus.write_byte_data(ADDR, DIRB, 0x00) | |
bus.write_byte_data(ADDR, PORTB, 0x00) | |
#initialize Minecraft | |
mc = minecraft.Minecraft.create() | |
#create a scheduler | |
s = sched.scheduler (time.time, time.sleep) | |
#looped function | |
def minimap_cycle(sc): | |
#get the position and realign it so 0,0 is at a corner and not the center and divide so it corresponds with an LED | |
#world size in minecraft pi is 256x256 | |
playerPos = mc.player.getPos() | |
ledX =(int(playerPos.x) + 128)/32 | |
ledY =(int(-playerPos.z) + 128)/32 | |
SetLED(ledX, ledY) | |
#call the function again in 1/10th of a minute | |
c.enter(0.1, 1, minimap_cycle, (sc,)) | |
#start running the function | |
s.enter(0.1, 1, minimap_cycle, (s,)) | |
s.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment