4
www.kitronik.co.uk
27
Next we will make a function where we can input a chosen number of
degrees and :MOVE mini will output a signal to the servos to turn through
the set number of degrees.
To do this, the function will:
1. Turn on the servos,
2. Wait a period of time,
3. Then turn them off.
The ‘timeToWait’ is calculated by taking the chosen number of degrees,
dividing it by how many degrees :MOVE mini turns per second, and then
converting the answer to microseconds so the micro:bit can understand
it. This value is then output to the servos, resulting in :MOVE mini turning
through the chosen angle.
STEP 3: Add the following code under the previous code.
STEP 4: Program button A to call the function we have just created:
Because :MOVE mini can’t tell how far it has turned, we have
to use time and a knowledge of how fast :MOVE mini turns
to make the turn accurately.
WHY WE NEED TO DO THIS
Now we have made the function, lets use it!
NOTE: There is a pause to allow
you to move your hand before
the :MOVE mini starts turning.