Created
December 31, 2015 23:43
-
-
Save KramKroc/a657e561a5c4deb24b75 to your computer and use it in GitHub Desktop.
Control color of RGB LED based on what player is standing on
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
from mcpi.minecraft import Minecraft | |
from time import sleep | |
from gpiozero import RGBLED | |
mc = Minecraft.create() | |
rgbled = RGBLED(26,19,13) | |
# block | |
grass = 2 | |
ice = 9 | |
sand = 12 | |
# colours | |
green = (0, 1, 0) | |
blue = (0.1, 0.1, 0.1) | |
yellow = (1, 1, 0) | |
# block: colour | |
colours = { | |
grass: green, | |
ice: blue, | |
sand: yellow, | |
} | |
while True: | |
sleep(0.1) | |
p = mc.player.getTilePos() | |
block = mc.getBlock(p.x, p.y-1, p.z) | |
if block in colours: | |
colour = colours[block] | |
rgbled.color = colour | |
else: | |
rgbled.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment