VMM502
V. 01 – 17/01/2019
11
©Velleman nv
Step 4
Click on
Tinkercademy
or
OLED
inside the
Code Drawer
to find our custom blocks for the various
components in your kit.
Next, let’s create a conditional statement
if then else
as shown in the picture. You will find this block in
the
Logic
section of the Code Drawer.
The code shown below means that, when button A is pressed on the ADKeypad while the ADKeypad is
plugged in at pin 2 (P2) of the BoB, the buzzer will play a sound of 175 Hertz.
Since there are 5 buttons, we need to code 5 similar conditional statements. Each button ‘controls’ a
sound of a particular pitch and so pressing each button produces sounds of different pitches.
When complete, we compile the programme to generate a .hex file. Click on the download button and
save the .hex file to the
Downloads
folder (C:\downloads). This .hex file is ready to be uploaded to the
micro:bit.
Plug the micro:bit into the USB port via the micro-USB cable. Then, drag and drop the .hex-file (from
the
Downloads
folder) onto the micro:bit
Removable device
to upload the programme.
Now, you can play music by pressing the keys on the ADKeypad. Enjoy!