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 pet16Button A is always selected by default.Button A is what we want to press to activatethe ASLEEP state so you don’t need to changeanything in the code here.PREVIEW17We now need to add our set sleep functioninside the IF statement. Select do nothingwithin the IF code. On the keyboard presscode and then select your function for sleep.18We now need to tell our pet what to do when we’renot pressing button A. Select the else do nothingcode. On the keyboard, click code and then yourset awake function.19For the purpose of testing, let’s include a pause for5000 milliseconds (5 seconds). In your code, clickon your set sleep function. Click on the + buttonbelow it. Now click on micro:bit on the keyboardand select the pause button. Replace 100 with5000.Do your own thing!- Can you add in another IF condition which will feed your pet?- Try using the image editor to create key frames which make your digital pet’s mouth move when it is EATING.• Can you make use of the scrolling text so that you know when your digital pet is going to wake up?Try micro:bit->show string.• Can you program your pet to say that he is hungry after 60 seconds?• Can you use a variable to count how many times you’ve fed your pet? Use the buttons to check your total.A solution for the complete digital keyring code can be found on page 27. The workingcode can be found at live.microbit.co.uk/start-guide/solutions/digital-pet.19

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

Saved successfully!

Ooh no, something went wrong!