Draw A Shape Using Javascript - Kitronik BBC Micro Bit move Mini Mk2 Manual

Hide thumbs Also See for BBC Micro Bit move Mini Mk2:
Table of Contents

Advertisement

9

DRAW A SHAPE USING JAVASCRIPT

A square has four equal sides, and four 90 degree corners.
Instead of writing the same code four times for both the sides
and the corners, we can save some time by writing control
functions! This means we can write the code once, and then
tell the program to refer back to it as many times as we want.
STEP 1: Click on the 'JavaScript' button towards the top of your browser.
This will activate the JavaScript programming environment, and allow us to
write some code.
STEP 2: Create the following constants. We will use these to store some
information about :MOVE mini.
VARIABLES EXPLAINED
MICROSEC_IN_A_SEC - The micro:bit's processor counts
time in 'micro seconds'. We want to be counting in 'seconds'
so we will need to convert this. 1sec = 1million microsecs.
DISTANCE_PER_SEC - We will use this to calibrate how far
:MOVE mini travels in one second.
DEGREES_PER_SEC - We will use this to calibrate how far
:MOVE mini turns in one second.
These will allow us to tune the code to our individual :MOVE mini. For
example, if :MOVE mini turns past 90° when we code 'turn right', we can
adjust these values to correct it easily.
26

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BBC Micro Bit move Mini Mk2 and is the answer not in the manual?

Table of Contents

Save PDF