Dual Digit 7 Segment Display

Dependencies:   mbed

Committer:
amos
Date:
Tue Oct 12 22:08:37 2010 +0000
Revision:
1:4d9d638b8e3f
Parent:
0:71cc75eb9510
Countdown from 99 to 00 on the display

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amos 1:4d9d638b8e3f 1 /**************************************************************************
amos 1:4d9d638b8e3f 2 ***************************************************************************
amos 1:4d9d638b8e3f 3
amos 1:4d9d638b8e3f 4 Countdown from 99 to 0 on a dual digit 7 segment display
amos 1:4d9d638b8e3f 5 by Amos 12/10/2010 (that's October 12th!)
amos 1:4d9d638b8e3f 6
amos 1:4d9d638b8e3f 7
amos 1:4d9d638b8e3f 8 ***************************************************************************
amos 1:4d9d638b8e3f 9 ***************************************************************************/
amos 1:4d9d638b8e3f 10
amos 0:71cc75eb9510 11 #include "mbed.h"
amos 0:71cc75eb9510 12
amos 1:4d9d638b8e3f 13 DigitalOut myLeftPins[] = {p7, p8, p9, p10, p11, p12, p13};
amos 1:4d9d638b8e3f 14 DigitalOut myRightPins[] = {p14, p15, p16, p17, p18, p19, p20};
amos 0:71cc75eb9510 15
amos 0:71cc75eb9510 16 /*
amos 1:4d9d638b8e3f 17 Individual numerals
amos 0:71cc75eb9510 18 int zero[] = {0, 0, 0, 1, 0, 0, 0};
amos 0:71cc75eb9510 19 int one[] = {0, 1, 1, 1, 1, 1, 0};
amos 0:71cc75eb9510 20 int two[] = {1, 0, 0, 0, 0, 1, 0};
amos 0:71cc75eb9510 21 int three[] = {0, 1, 0, 0, 0, 1, 0};
amos 0:71cc75eb9510 22 int four[] = {0, 1, 1, 0, 1, 0, 0};
amos 0:71cc75eb9510 23 int five[] = {0, 1, 0, 0, 0, 0, 1};
amos 0:71cc75eb9510 24 int six[] = {0, 0, 0, 0, 0, 0, 1};
amos 0:71cc75eb9510 25 int seven[] = {0, 1, 1, 1, 0, 1, 0};
amos 0:71cc75eb9510 26 int eight[] = {0, 0, 0, 0, 0, 0, 0};
amos 0:71cc75eb9510 27 int nine[] = {0, 1, 0, 0, 0, 0, 0};
amos 0:71cc75eb9510 28 */
amos 0:71cc75eb9510 29
amos 1:4d9d638b8e3f 30 //This is an array of arrays where the first index into the array
amos 1:4d9d638b8e3f 31 //locates the pin combination which displays that digit
amos 1:4d9d638b8e3f 32 //eg numb[1] returns the array containg the segments to display 1.
amos 0:71cc75eb9510 33 int numb[10][7] = {{0, 0, 0, 1, 0, 0, 0},
amos 0:71cc75eb9510 34 {0, 1, 1, 1, 1, 1, 0},
amos 0:71cc75eb9510 35 {1, 0, 0, 0, 0, 1, 0},
amos 0:71cc75eb9510 36 {0, 1, 0, 0, 0, 1, 0},
amos 0:71cc75eb9510 37 {0, 1, 1, 0, 1, 0, 0},
amos 0:71cc75eb9510 38 {0, 1, 0, 0, 0, 0, 1},
amos 0:71cc75eb9510 39 {0, 0, 0, 0, 0, 0, 1},
amos 0:71cc75eb9510 40 {0, 1, 1, 1, 0, 1, 0},
amos 0:71cc75eb9510 41 {0, 0, 0, 0, 0, 0, 0},
amos 0:71cc75eb9510 42 {0, 1, 0, 0, 0, 0, 0}};
amos 0:71cc75eb9510 43
amos 0:71cc75eb9510 44 int main()
amos 0:71cc75eb9510 45 {
amos 0:71cc75eb9510 46 while(1)
amos 0:71cc75eb9510 47 {
amos 1:4d9d638b8e3f 48 for(int i = 0; i < 7; i++)
amos 0:71cc75eb9510 49 {
amos 1:4d9d638b8e3f 50 //clear all pins
amos 1:4d9d638b8e3f 51 myLeftPins[i] = 1;
amos 1:4d9d638b8e3f 52 myRightPins[i] = 1;
amos 1:4d9d638b8e3f 53 }
amos 1:4d9d638b8e3f 54 //Countdown loop
amos 1:4d9d638b8e3f 55 for(int x = 99; x >= 0; x--)
amos 1:4d9d638b8e3f 56 {
amos 1:4d9d638b8e3f 57 //set the main counter
amos 0:71cc75eb9510 58 for(int i = 0; i < 7; i++)
amos 0:71cc75eb9510 59 {
amos 1:4d9d638b8e3f 60 //Left digit displays the value of x/10 ie the tens column
amos 1:4d9d638b8e3f 61 myLeftPins[i] = numb[x/10][i];
amos 1:4d9d638b8e3f 62 //Right digit displays the value of x%10 ie the units column
amos 1:4d9d638b8e3f 63 myRightPins[i] = numb[x%10][i];
amos 0:71cc75eb9510 64 }
amos 1:4d9d638b8e3f 65 //1 second
amos 0:71cc75eb9510 66 wait(1);
amos 0:71cc75eb9510 67 }
amos 0:71cc75eb9510 68 }
amos 0:71cc75eb9510 69 }
amos 0:71cc75eb9510 70
amos 0:71cc75eb9510 71