|Micro:bit Getting Started With C/C++|
|Written by Harry Fairhead|
|Monday, 05 September 2022|
Page 4 of 4
Your First Program - Blinky
The time has come to run your first program and deal with some details of using VS Code.
You can use either the V1 or V2 development environment and hence target either version of the micro:bit. It is assumed that you have set up a project called BlinkyV1 or BlinkyV2 following the instructions given earlier. Load the project into VS Code and do a clean configure and a clean rebuild. Next, delete all of the source files in the source directory, which is in the project root for both versions. Create a new file called
Exactly the same code will work with the V1 or the V2 micro:bit. Do a clean reconfigure and a clean rebuild of the project. As usual you will see a lot of warnings scroll past for the V1 compile, but the build should finish without errors.
You will find the generated hex files in \BlinkyV1\build\source for the V1 program and the file that you want to download is BlinkyV1-combined.hex.
For the V2 program you will find the hex file in the project root and it is called MICROBIT.hex.
If you have set the templates up correctly, you should see the middle LED in the display flash at 1 second intervals. Notice that if you simply change the main program, or make minor changes to any program in the project, you should only need to do a build and not a clean build.
Everything should work as advertised, including IntelliSense, auto-complete and error flagging. If not make sure that the.vscode\c_cpp_properties.json file contains the line:
Assuming that you have built both the Blinky program for V1 and V2, we can create a universal hex file that can be loaded into either version of the micro:bit. The simplest way of doing this is to go to the web page:
and drag and drop the appropriate hex files:
Notice that these have to be the Intel hex files and not the combined file produced for the V1 microbit.
When you click the create universal hex button you are asked to provide a location for the file. Once downloaded you can drag and drop the hex file into either a V1 or a V2 micro:bit and it will work.
Micro:bit IoT In C Second Edition
By Harry Fairhead
Buy from Amazon.
Summer SALE Kindle 9.99 Paperback $10 off!!
or email your comment to: email@example.com
|Last Updated ( Monday, 05 September 2022 )|