Introduction
Connect two pushbuttons to a Bit Board and control an LED with code.
We'll explore how we can use two pushbuttons as inputs for the micro:bit
Video Overview
Featured Document
-
-
We'll use Maker Tape to connect the two Buttons and the LED to the Bit Board on a LEGO baseplate.
-
We'll connect our LED to Pin 1 and one of our Buttons to Pin 4 and the other to Pin 5.
-
And of course we'll connect the Ground (GND) sides of each component to Ground 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.
-
While the LED has Polarity our Button does not. If you connect it the other way around it will still work fine. Not all components have Polarity.
-
-
-
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 Two Buttons LED program: https://makecode.microbit.org/_YqR0EYboq...
-
This code will blink the LED 6 times if you press the left button and 3 times if you press the right button.
-
We are using an if then block checking for the button on Pin 4 to be pressed (pulled down to ground), or for the button on Pin 5 to be pressed, and if their is true the else gets triggered and the LED is set to off (or "0" or "low").
-
We've also used the repeat block to easily make the LED blink either 6 or 3 times.
-
-
-
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 LED should turn on and blink either 6 times or 3 times depending on which button you press.
-
-
-
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/live/_QU-qXrxYr4...
-
