Dual Digit 7 Segment Display
.
Hardware
LED Bright BD-A405ND Dual Digit 7 Segment Display
Has 16 pins 8 above and 8 below the display.
Pin 1 is in the bottom left hand corner, pins are numbered anti-clockwise to 16 in the top left hand corner (picture to follow).
Pins 4 and 5 power the display, these are linked to vout on the mbed.
Left Digit
Pins connected as follows
p7----------------LED Pin 1
p8----------------LED Pin 2
p9----------------LED Pin 3
p10--------------LED Pin 16
p11--------------LED Pin15
p12--------------LED Pin14
p13--------------LED Pin13
Right Digit
Pins connected as follows
p14--------------LED Pin 8
p15--------------LED Pin 7
p16--------------LED Pin 6
p17--------------LED Pin 9
p18--------------LED Pin 10
p19--------------LED Pin 11
p20--------------LED Pin 12
Set a pin to 0 to light it, 1 to clear it.
I've deliberately made sure that pins 14 to 20 light up the same segments on the right digit as the left in order to be able to reuse the same array of arrays to calculate how to show the digit.
To count down from 99 to 00 on the display at one digit per second:
/************************************************************************** *************************************************************************** Countdown from 99 to 0 on a dual digit 7 segment display by Amos 12/10/2010 (that's October 12th!) *************************************************************************** ***************************************************************************/ #include "mbed.h" DigitalOut myLeftPins[] = {p7, p8, p9, p10, p11, p12, p13}; DigitalOut myRightPins[] = {p14, p15, p16, p17, p18, p19, p20}; /* Individual numerals int zero[] = {0, 0, 0, 1, 0, 0, 0}; int one[] = {0, 1, 1, 1, 1, 1, 0}; int two[] = {1, 0, 0, 0, 0, 1, 0}; int three[] = {0, 1, 0, 0, 0, 1, 0}; int four[] = {0, 1, 1, 0, 1, 0, 0}; int five[] = {0, 1, 0, 0, 0, 0, 1}; int six[] = {0, 0, 0, 0, 0, 0, 1}; int seven[] = {0, 1, 1, 1, 0, 1, 0}; int eight[] = {0, 0, 0, 0, 0, 0, 0}; int nine[] = {0, 1, 0, 0, 0, 0, 0}; */ //This is an array of arrays where the first index into the array //locates the pin combination which displays that digit //eg numb[1] returns the array containg the segments to display 1. int numb[10][7] = {{0, 0, 0, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 0}, {1, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1, 0}, {0, 1, 1, 0, 1, 0, 0}, {0, 1, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1}, {0, 1, 1, 1, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0}}; int main() { while(1) { for(int i = 0; i < 7; i++) { //clear all pins myLeftPins[i] = 1; myRightPins[i] = 1; } //Countdown loop for(int x = 99; x >= 0; x--) { //set the main counter for(int i = 0; i < 7; i++) { //Left digit displays the value of x/10 ie the tens column myLeftPins[i] = numb[x/10][i]; //Right digit displays the value of x%10 ie the units column myRightPins[i] = numb[x%10][i]; } //1 second wait(1); } } }
A picture of the countdown clock.
Download this code here:
The countdown is at least as accurate time-wise as the stop watch on my (analogue) wrist-watch.
Things I might do with this now:
Add some buttons to start/stop/pause/set the countdown.
Make a counter upper (pushing a button adds one to the count).
Add a speaker/buzzer to sound an alarm when the count down is done.
6 comments
You need to log in to post a comment
I'm suprised it took this long for someone to publish something with 7-segment displays.. I guess LCD displays ruined us :P