Guide

3/7/2018 SparkFun Inventor's Kit for micro:bit Experiment Guide - learn.sparkfun.com
https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-for-microbit-experiment-guide/all#introduction-to-microsoft-makecode 57/63
Note: You may need to disable your ad/pop-up blocker to interact with the MakeCode programming environment and
simulated circuit!
Code to Note
Let’s take a look at the code blocks in this experiment.
If you are having a hard time viewing this code, click on the image above to get a better look!
Acceleration
The acceleration block can be found under the input blocks group. This block returns the force of gravity pulling on a specific
axis of the micro:bit (X, Y or Z) and represents that value as a range of numbers between -1023 and 1023. In this case, we
measure the X axis, which is the side-to-side tilt of the micro:bit. If you tilt the micro:bit all the way to the left, you will get a -1023
value and all the way to the right is positive 1023.
Map
The map block looks intimidating, but it is one of the most useful blocks in MakeCode. The map block takes a given variable
that has a known range — in this case -1023 to 1023 — and “maps” or scales that value range to another given range. The given
range we want is 15 to 165, which is a good safe range of rotation for the servo. So, in the end -1023 ends up to equal 0, and
1023 ends up as 165 from the map block.