BBC micro:bit Counter using a 7-Segment Display

7-segment-displayThe aim of this challenge is to create a countdown timer, controlled by a BBC micro:bit that will display the numbers on a screen using a 7-segment display. A lot of electronic devices use this approach to display numbers on a LED or LCD screen. (Watch, alarm clock, calculator etc.)

Typically 7-segment displays consist of seven individual coloured LED’s (called the segments). Each segment can be turned on or off to create a unique pattern/combination. Each segment is identified using a letter between A to G as follows:

7segments

The following truth table shows which segments need to be on to display the digits from 0 to 9:

Digit A B C D E F G
tmp-0 1 1 1 1 1 1 0
tmp-1 0 1 1 0 0 0 0
tmp-2 1 1 0 1 1 0 1
tmp-3 1 1 1 1 0 0 1
tmp-4 0 1 1 0 0 1 1
tmp-5 1 0 1 1 0 1 1
tmp-6 1 0 1 1 1 1 1
tmp-7 1 1 1 0 0 0 0
tmp-8 1 1 1 1 1 1 1
tmp-9 1 1 1 1 0 1 1

Step 1: The electronic circuit


7-segment-display-connectionsTo complete this challenge you will need:

  • 1 breadboard
  • 8 resistors of 220Ω each
  • 1 7-segment display (common anode)
  • 1 BBC micro:bit
  • 1 micro:bit edge connector
  • 20 wires

Here is the circuit that you will need to re-create:
micro-bit-7-segment

Step 2: Python Code

To program your BBC micro:bit you will use the Python editor and copy and paste the following code:

#micro-bit Counter using a 7-Segment Display - www.101computing.net
from microbit import *

pins = [pin0, pin1, pin2, pin8, pin12, pin13, pin14, pin15]
digits = ["11111100","01100000","11011010","11110010","01100110",
          "10110110","10111110","11100000","11111110","11110110"]

while True:
    for i in range(0,10):
        bits=digits[i]
        for j in range(0,8):
            pins[j].write_digital(int(bits[j]))
        display.scroll(str(i))
        sleep(1000)

Your 7-segment display should display all the digits, counting up from 0 to 9.

Your Challenge


countdown_animatedUpdate the code to:

  • Create a count down timer, going from 9 to 0.
  • Allow the user to pause and restart the countdown timer using the A and B buttons of the micro:bit.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 14

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: