The 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:
The following truth table shows which segments need to be on to display the digits from 0 to 9:
Step 1: The electronic circuit
To 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:
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.
Update 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.