Skip to content

Instantly share code, notes, and snippets.

@KramKroc
Created December 31, 2015 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KramKroc/a657e561a5c4deb24b75 to your computer and use it in GitHub Desktop.
Save KramKroc/a657e561a5c4deb24b75 to your computer and use it in GitHub Desktop.
Control color of RGB LED based on what player is standing on
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