Introduction
Connect a 7 Segment Display and a Push Button to a Bit Board and control them with code.
We'll explore code to control a 7 Segment Digital Display that can show numbers up to 9999.
Video Overview
-
-
We'll connect the 7 Segment Display with a Crazy Circuits Ribbon Cable using all four wires.
-
Start by plugging the connector with the three wires in it (Black, Red, Yellow) into the Pin 1 row of the Bit Board. (Make sure the Black wire is in - and the Yellow wire labeled S1 is closest to the number 1 on the Bit Board.) We can then plug the Orange wire labeled S2 into Pin 0 on the Bit Board.
-
Now we'll connect the other end of the Ribbon Cable to the 7 Segment Display. The pin labels are on the back of the 7 Segment Display PCB. From top to bottom it's CLK, DIO, VCC, GND.
-
CLK stands for Clock and DIO stands for Data Input/Output. VCC is the Positive (+) and GND is the Ground (-) or Negative.
-
S2 (Orange) goes to CLK, S1 (Yellow) goes to DIO, and then + (Positive) goes to VCC and - (Ground or Negative) goes to GND.
-
Make sure every wire is connected in the correct place, or our display will not work!
-
We'll use Maker Tape to connect the Button to the Bit Board on a LEGO baseplate. Connect the Button to Pin 5 and to Ground (GND).
-
-
-
We used a 3D printed holder we designed to hold the 7 Segment Display in place on the LEGO baseplate.
-
You can find the guide for the holder here: 7 Segment Display Holder
-
Alternately you can use some LEGO bricks and a rubber band or tape to hold the display in place.
-
-
-
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 7 Segment Count Press program: https://makecode.microbit.org/_APaKwA488...
-
In the on start block we'll set up our display using the pins we've connected. CLK to Pin 0 and DIO to Pin 1. (We'll also set up a few more things we need for our program.)
-
We've added a bit more logic into our forever loop. We will read the state of Pin 5 and assign it to the variable buttonValue. (It will be either 1 or 0.)
-
We then check if the value of buttonValue is 0, meaning the button has been pressed. (When the button is not being pressed the value will be 1.)
-
When the if statement is true we will call the countUp function to increase and display the number, and then we'll get stuck in the while loop as long as the buttonValue remains 0, which means the button is still being held down.
-
In the while loop we continually check to see if the buttonValue changes, by reading Pin 5. When the button is released the value becomes 1, and is no longer 0, so the while loop ends.
-
-
-
Once the code is loaded it should start running immediately and the 7 Segment Display should show
0000. -
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.
-
Press the button and the number will increase.
-
There are not really any "gotchas" with this version. You should be able to do the following:
-
Press the button and hold it down
-
Press the button repeatedly in rapid succession
-
And it should always work as expected, increasing the number by one, and not doing it again until you release and press the button again.
-
-
-
Follow along with our recorded Live Stream!
-
(We'll add the video to this step after we do the stream!)
-
