The aim of this blog post is to create a countdown timer that will display the numbers on 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.)
First we need to investigate how the 7-segment display works. You will find this page quite useful.
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:
Digit | A | B | C | D | E | F | G |
1 | 1 | 1 | 1 | 1 | 1 | 0 | |
0 | 1 | 1 | 0 | 0 | 0 | 0 | |
1 | 1 | 0 | 1 | 1 | 0 | 1 | |
1 | 1 | 1 | 1 | 0 | 0 | 1 | |
0 | 1 | 1 | 0 | 0 | 1 | 1 | |
1 | 0 | 1 | 1 | 0 | 1 | 1 | |
1 | 0 | 1 | 1 | 1 | 1 | 1 | |
1 | 1 | 1 | 0 | 0 | 0 | 0 | |
1 | 1 | 1 | 1 | 1 | 1 | 1 | |
1 | 1 | 1 | 1 | 0 | 1 | 1 |
Your Challenge
The code below is used to display a countdown timer counting from 5 to 0 and using the 7-segment approach to display the numbers.
Your challenge consists of using the truth table given in this post to start your countdown from 9 (instead of 5).
Challenge #2:
With 7 segments there are 128 possible symbols. Some can be used to represent letters. For instance:
Tweak the code above to write a message using the 7-segment display.
Start with the following message “Hello” (HELLO)