Introduction
Connect four LEDs to a Bit Board and control them with a micro:bit
We'll use the random function to make one LED light up.
Video Overview
Featured Document
-
-
We'll use Maker Tape to connect the LEDs to the Bit Board on a LEGO baseplate.
-
Connect the Negative (-) sides of the LEDs to a Ground (GND) hole on the Bit Board.
-
Connect the Positive (+) side of the first LED to Pin 1 on the Bit Board.
-
Connect the Positive (+) side of the second LED to Pin 2 on the Bit Board.
-
Connect the Positive (+) side of the third LED to Pin 3 on the Bit Board.
-
Connect the Positive (+) side of the fourth LED to Pin 4 on the Bit Board.
-
You'll notice the Ground on the Bit Board (as well as the LED and other Crazy Circuits components we'll use) is color coded White.
-
-
-
If you've never used a micro:bit before you'll want to check out this guide: Bit Board V2 Setup and Use
-
We're going to load the following code for our LED Blink Randomly program: https://makecode.microbit.org/_bJ3PCuadw...
-
This code will generate a random number between 1 and 4 and then light up the corresponding LED. It will then turn off all of the LEDs and repeat the process.
-
At the beginning of our forever block we use a set to function and then add a pick random function to it. We then use an if then block to turn on the specific LED.
-
Finally, we'll use a math function to do some simple division in the last line of the forever block.
-
You'll notice we have a command for led enable set to false in the on start block. The led enable command enables or disables the built-in LED matrix on the front of the micro:bit
-
We need to turn off the built-in LED matrix to properly use Pin 3 and Pin 4 otherwise they will be used by the built-in LED matrix and conflict with our code to control our LEDs.
-
You can see a description of the micro:bit pins here: https://makecode.microbit.org/device/pin...
-
-
-
Once the code is loaded it should start running immediately.
-
You can power the micro:bit via the USB cable you used to load the code or you can use a battery pack plugged into the Bit Board.
-
The code will start by choosing a random number between 1 and 4 and then using the if them block will it will turn on the appropriate LED, then turn it off, and repeat.
-
In future guides we'll use four LEDs along with sensors or other input to act as a small bar graph or level indicator.
-
-
-
Follow along with our recorded Live Stream!
-
You can watch the full video of us walking through this project, along with explaining and exploring the code: https://www.youtube.com/watch?v=_ArsMH4A...
-
