David Ames
/
myflashy
Dual Digit 7 Segment Display
Revision 1:4d9d638b8e3f, committed 2010-10-12
- Comitter:
- amos
- Date:
- Tue Oct 12 22:08:37 2010 +0000
- Parent:
- 0:71cc75eb9510
- Commit message:
- Countdown from 99 to 00 on the display
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 71cc75eb9510 -r 4d9d638b8e3f main.cpp --- a/main.cpp Mon Oct 11 22:09:37 2010 +0000 +++ b/main.cpp Tue Oct 12 22:08:37 2010 +0000 @@ -1,8 +1,20 @@ +/************************************************************************** +*************************************************************************** + +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 myPins[] = {p7, p8, p9, p10, p11, p12, p13}; +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}; @@ -15,6 +27,9 @@ 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}, @@ -28,18 +43,26 @@ int main() { - for(int i = 0; i < 7; i++) - { - myPins[i] = 1; - } while(1) { - for(int k = 0; k < 10; k++) + 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++) { - myPins[i] = numb[k][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); } }