16.07.2015 Views

MicroBit-Quick-Start-Teacher-Guide

MicroBit-Quick-Start-Teacher-Guide

MicroBit-Quick-Start-Teacher-Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Challenge 2: Digital petChallenge 2: Digital petPREVIEWProgramming an animated pet using variables and functionsOutcomeA digital pet (similar to Tamagotchis from the 90s) withdifferent states that can be controlled by pressingbuttons A and B (our input). The idea is that our digitalpet has demands for attention. In this example ourdifferent states will represent some of these demands:- The default state of the pet is AWAKE.- Button A will stroke the pet, causing it to fall ASLEEP.- Button B will feed the pet, so it is EATING.TutorialsDecomposing the problemThis challenge can be decomposed into four parts:1. Design how each state will look(which LEDs will be switched on).2. Create a function which tells our BBC micro:bitwhich LEDs to turn on for each state.3. Create a while loop to continue showing a stateuntil a different button is pressed.4. Create conditional statements to specify whichfunction to run if a particular button is pressed,e.g. if input A pressed then go to ASLEEP state.For a video tutorial go to live.microbit.co.uk/start-guide/video-tutorials/digital-petFor a guided coding tutorial go to live.microbit.co.uk/td/tutorials/digital-petDesign how each state will lookBefore we start to code, we need to plan out what our pet will look like for each state.01Draw a 5 × 5 grid and colour in the lights toshow what your pet will look like at different times,for example: AWAKE, ASLEEP, EATING(as shown right).AWAKE SLEEPING EATING02<strong>Start</strong> by opening a new browser window and typinglive.microbit.co.uk in the address bar. Click onCreate Code. In TouchDevelop, click New project.Type in a name for your script, such as Digitalpet. Click on create.Create a function for each stateWe’re going to start by programming a function for the different states of our digitalpet (e.g. which LEDs are ON and which are OFF for each state). We’re going to dothis first because we will want to call on these functions later, without having to leavethe main process.15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!