Blinking an LED by Coding BBC Micro:bit
Do you like coding with your BBC micro:bit ? Of course, YES. It can make learning easy and fun. It is very simple to assemble and play your first program about micro:bit. Try it and you will get more delight with your code!
Today I am going to show my first program about BBC micro:bit. Actually it is my first time to code with micro:bit using Blocks. I am a starter, a young green-hand in programming study. Since the BBC micro:bit program becomes much more easier, everyone no matter the adults or kids can play with it.
In the following, I will show you a simple LED blinking display. Want to see how I make it? Let's just take a look! Enjoy the time to code with micro:bit!
First of all, I need to prepare all the components that used in this program.
1. micro:bit main board *1
2. keyestudio T-type adapter *1
3. USB cable *1
4. LED *1
5. 220Ω resistor *1
6. Breadboard *1
7. Breadboard jumper wire *2
Prepared well all the components, next step we can start to connect all of them. Quite easy to hook up as the following picture shown.
Firstly, insert the micro:bit into the keyestudio T-type adapter, then plug them into the medium breadboard.
Plug an LED into the breadboard, then connect one end of a 220Ω resistor to the cathode pin of LED, another end of resistor is connected to ground (GND). while the anode pin of LED is connected to Pin 9 of adapter.
After finished wiring, we can get the connection example as follows:
Then, I connect the micro:bit to my computer using a USB cable.
After that, I search for the micro:bit MakeCode on my browser page. Choose the Blocks option.
This time I am ready to make the code that can make the external LED blink. You can see there are many options on the code drawer.
To begin with code as follows:
At first, drag the on start block from the Basic
Then select Led- More to find led enable false, drag this block into the on start loop.
You can get this as below:
What's more, drag the forever block from the Basic
Then select the Pins to find the block digital write pin () to (), and drag this block into the forever loop.
Here we set the pin 9 to high level 1 because in the wiring we connect the pin 9.
You can get the figure shown below:
After that, I look into the Basic again to find the block pause (ms) and drag it into forever loop. And here we set the pause time as 500ms.
This time we can right-click the mouse to duplicate the block digital write pin () to () and pause (ms). And set the digital write pin 9 to low level 0.
Finally get the complete program shown below.
Till this step, the code is done well. Next, let's save the code.
You can pick a name for this program and then click download in the bottom area of MakeCode page.
Finally we send the code into micro:bit main board. You can see the external led start to blink.
Quite amazing, right? This little program is indeed simple. Have a try, you can get delight with it while playing the code!