BitIO blog 7: Minecraft CPU temperature monitor
David Whale has been busy crafting more add on's to his BitIO library for the MIcro:bit. A few days ago he added the Micropython function to check the CPU temperature. His library can be accessed from here:
Here is the link to the code:
I have built / recycled Minecraft graphing code to create a CPU temperature monitor. Every time you press the a button it takes a temperature reading and then out puts this to Minecraft as a random coloured wool bar. Here is what you end up with:
1. Open python 3 on the Raspberry Pi.
2. Plug your Micro:bit into the Pi/PC.
3. Ensure that you have read blog 1:
http://warksjammy.blogspot.co.uk/2017/07/blog-1-getting-started-with-bitio.html
and downloaded the BitIO master files from David Whales github
4. Go into the 'Bitio master' folder, find the 'src' folder
5. Create a new Python 3 script.6. Call it "Minecraft CPU temperature monitor.py"
7. Type in the following code:
Code
import microbit from mcpi import minecraft as minecraft from mcpi import block as block import time import random WoolList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] mc = minecraft.Minecraft.create() orx,ory,orz = mc.player.getPos() mc.postToChat("Start Graph") TempBlock = 35,14 HumidityBlock = 35,3 Temperature_List = []#stores temp data DataStreamCount= 0 def BuildDataBlockTemp(ImportedBlock):# take data for temp temp = int(microbit.temperature()) Temperature_List.append(temp) orx,ory,orz = mc.player.getPos() for i in range (0,temp): x,y,z = mc.player.getPos() mc.setBlock(x+30,i,z,35,ImportedBlock) mc.player.setPos(orx,ory,orz+1) msg = "Temp = {0}".format(temp) print(msg) while True: time.sleep(0.25) if microbit.button_a.was_pressed(): TempBlock = random.choice(WoolList) BuildDataBlockTemp(TempBlock)
8. Open Minecraft, create a new world.
9. Run the code by pressing f5, checking for any errors that arise.
10. Press the a button on the Micro:bit.
Extension:
Try automating the graph so that it carries on every 10 seconds
You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf
No comments:
Post a Comment