16.07.2015 Views

MicroBit-Quick-Start-Teacher-Guide

MicroBit-Quick-Start-Teacher-Guide

MicroBit-Quick-Start-Teacher-Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Challenge 3: Catch the egg gameChange the position of the basketusing the accelerometer functionalityPREVIEWIt’s now time to change the position of the basket. You can do this by using the accelerometerwithin the BBC micro:bit. You may have used an accelerometer in your smartphone whenplaying games previously. Have you ever had to play a maze game where you escort theball into the hole?20We’re going to add the next line of code abovethe pause. Select micro:bit from the keyboard. Touse the accelerometer you will need to select theacceleration button. Now select store in var. Theprogram sets the acceleration to left and right. Thisis the default position (x); you can also control upand down (y). You should have something like this:21We now need to work out the position of theaccelerometer and then turn the LED on.Select the x variable from the data menu in thekeyboard. Select the assignment (:=) button.22Type in number 2, + and then select the mathlibrary from the menu at the bottom. We needthe math library in TouchDevelop so that we cando our rounding and work out the position of theaccelerometer.23Select the min button. Replace the first numberwith 2 and then math and then max. This codeis finding the highest and lowest values that theboard could move to the left and right. You shouldhave something like the picture, right.24To finish, we need to replace the maximum valueswith −2 and then the variable we created. In thiscase it’s called millig. Divide it by 200.25

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

Saved successfully!

Ooh no, something went wrong!