Wednesday, 21 February 2018

Week 1 exercise 2 functions and buttons for micro:bit

This tutorial is an extention of the code introduction tutorial

Outcome:
Changing the image displayed on the micro:bit through pressing the A and B button

Links:
Code editor https://makecode.microbit.org/
How to copy files to the micro:bithttps://makecode.microbit.org/device/usb

Step 1 
Load the previous project by clicking 'projects' in the code block editor.

This will open the project manager interface, select Import file from the menu


Click 'Choose File' which opens your file browser and select the previous tutorial project file 'microbit-getting-started.hex' 


Step 2
Inputs from button A and B
Now that the code from the previous project has been loaded we can add the user input to the code.
Select Inputs from the menu, then 'on button A pressed', repeat this again so that there are two instances of the 'on button A pressed' code block.



Step 6
Now add two 'show icon' code blocks into the 'on button A pressed' code blocks. Make sure that you select two different images for 'show icon' code blocks, in this case a cross and tick were selected. 

Step 7
You can now test your project in the editor by pressing the buttons on the interactive micro:bit to the left of the editor. Pressing the A and B buttons will change the image displayed on the micro:bit


Step 8 
Go ahead and save the project file. Select  the text field next to the save button and type in buttonAB. This will be the file name for the project. Go ahead and click the save button to the right of this text field. This will download the code to you computer saving it as a .hex file. Copy this file to the micro:bit, as the data is transfered to the micro:bit a light will flash showing that a transfer is in progress. Visit https://makecode.microbit.org/device/usb for more information on uploading files to the micro bit.

Step 9
Now that the project has been upload to the micro:bit. Test it out. Pressing the buttons will change the displayed icon

No comments:

Post a Comment