Using the micro:bit edge-connector with MakeCode Arcade
2024-12-05 | By Kitronik Maker
License: See Original Project micro:bit
Courtesy of Kitronik
Guide by Kitronik Maker
Full micro:bit edge connector support has now been added to the MakeCode Arcade editor. To highlight this, Jake from our Dev team has put together a code example to demonstrate the functionality of the micro:bit IO under MakeCode Arcade.
The demonstration involves a modification of the “jumpy platformer” example.
We Used
Phototransistor
10kΩ Resistor
3 x AA Batteries
THE HARDWARE:
The Kitronik ARCADE for BBC micro:bit is a handheld gaming platform designed specifically for use with the BBC micro:bit and the MakeCode Arcade editor. The board breaks out the 0, 1, 2, 3V, GND pins of the micro:bit, these pins can be connected to with crocodile clips. It is these pins that the example code below utilises.
ADDING THE EDGE CONNECTOR AND SERVO EXTENSIONS:
The edge connector functionality can be added to the MakeCode editor as an extension. Start a new project, then then click on the cog icon in the top right of the editor and select Extensions. Type and enter edge-connector into the search bar. Once you've clicked the tile, a “pins” tab will now be available under the “advanced” tab.
The servo functionality can be added in the same way, typing, and entering servo into the search bar instead. Once you've selected the tile, servo will be added to the menu on the left.
SERVO DEMONSTRATION – RAISING A FLAG AT THE END OF THE LEVEL:
To demonstrate the output functionality of the edge connectors, I’ve reused the original servo example. In this, a flag (attached to a clippable servo) will be raised when the player reaches the end of the level. The flag will then be lowered when the player starts the next level. To achieve this, two servo blocks are used in the code – the first to raise the flag, and the second to lower it.
Our servo is attached to P0 on the edge connector, and we want to raise the flag at a 90° angle. We place the servo block from the servo tab at the start of the function related to when the player overlaps the flag, meaning the end of the level has been won. As we want to reset the position of the flag at the start of the next level, the flag is reset to a 0° angle right at the end of the function – meaning the next level has been started.
This results in our flag raising when the end of the level has been reached and is lowered at the end of the level: As demonstrated in this video.
ANALOG INPUT – LIGHT SENSOR:
To show that the edge connectors can also be used as an input to interact with the game, two very simple functions have been added to the game to interact with additional hardware. The additional hardware is a phototransistor and a 10K resistor, forming a potential divider. As the light on the phototransistor decreases, the resistance of the phototransistor increases. The result is that the voltage on pin P1 will begin to fall.
To interact with the game, we can use the existing block “on pin” to select P1 from the first drop down list, and to also select “fall” from the second. This will enable an action to take place in the game when the phototransistor is covered. In this case, we have set the background to change from a Light Blue background to a Black background to simulate night.
When the phototransistor is uncovered, and the voltage on pin P1 begins to rise, a similar function is needed to change the background back from black to light blue.
©Kitronik Ltd – You may print this page & link to it but must not copy the page or part thereof without Kitronik's prior written consent.
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum