Wednesday, 9 August 2017

BitIO Blog 6: 'Touching pins....takes you places'

Part 2: Touching pins.....takes you places.

This takes the basic '' demo from David Whales BitIO master available here:

As ever if you have not quite noticed may playground is Minecraft. This version builds on from the previous blog about 'touching pins'

In this version you will touch a Micro:bit pin 0-2 and either:

  • pin 0- build the world map in Minecraft.
  • pin 1- teleport to England.
  • pin 2- teleport to the USA.

To "touch a pin" you will need to touch pin 0 for example with one finger and complete the circuit by touching the 'gnd' pin and then the code will work. 

Here is a link to a video of what touching pins basic code does:

Here is a photo of how it will look:

Here is the link to the simple version code:
Teleportation and pin reading code

Build world code:

Data file:

Credit Damien Mooney's world building code:

1. Plug your Micro:bit into the Pi/PC.
2.   Ensure that you have read blog 1:
and downloaded the BitIO master files from David Whales github

3. Go into the 'Bitio master' folder, find the 'src' folder 
4. Create a new Python 3 script.
5. Call it "touching pins takes you"
6. Type in the following code:

# - demonstrates using pin touch

import microbit

from mcpi import minecraft as minecraft
from mcpi import block as block
from datetime import datetime
import time
import serial
import random
import BuildWorldDM as bw

WoolList =[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
EngX = 1.0
EngZ = 50.0

UsaX = 53.8
UsaZ = 39.7
mc = minecraft.Minecraft.create()
def Teleport(x,z,Country):
    mc.setBlock(x,1, z,35,random.choice(WoolList))

while True:
    if microbit.pin0.is_touched():
        print("Pin 0 touched, build world")
    elif microbit.pin1.is_touched():
        print("Pin 1 touched, teleport to England")
    elif microbit.pin2.is_touched():
        print("Pin 2 touched, teleport to the USA") 

8. Open Minecraft, create a new world.
9. Run the code by pressing f5.
10. Try touching pin 0, what happens. Now try pin 1 and 2.

Try adding in extra countries.

You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:

No comments:

Post a comment