David Ames / Mbed 2 deprecated myflashy

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**************************************************************************
00002 ***************************************************************************
00003 
00004 Countdown from 99 to 0 on a dual digit 7 segment display
00005 by Amos 12/10/2010 (that's October 12th!) 
00006 
00007 
00008 ***************************************************************************
00009 ***************************************************************************/
00010 
00011 #include "mbed.h"
00012 
00013 DigitalOut myLeftPins[] = {p7, p8, p9, p10, p11, p12, p13};
00014 DigitalOut myRightPins[] = {p14, p15, p16, p17, p18, p19, p20};
00015 
00016 /*
00017 Individual numerals
00018 int zero[] = {0, 0, 0, 1, 0, 0, 0};
00019 int one[] = {0, 1, 1, 1, 1, 1, 0};
00020 int two[] = {1, 0, 0, 0, 0, 1, 0};
00021 int three[] = {0, 1, 0, 0, 0, 1, 0};
00022 int four[] = {0, 1, 1, 0, 1, 0, 0};
00023 int five[] = {0, 1, 0, 0, 0, 0, 1};
00024 int six[] = {0, 0, 0, 0, 0, 0, 1};
00025 int seven[] = {0, 1, 1, 1, 0, 1, 0};
00026 int eight[] = {0, 0, 0, 0, 0, 0, 0};
00027 int nine[] = {0, 1, 0, 0, 0, 0, 0};
00028 */
00029 
00030 //This is an array of arrays where the first index into the array
00031 //locates the pin combination which displays that digit
00032 //eg numb[1] returns the array containg the segments to display 1.
00033 int numb[10][7] = {{0, 0, 0, 1, 0, 0, 0},
00034                 {0, 1, 1, 1, 1, 1, 0}, 
00035                 {1, 0, 0, 0, 0, 1, 0}, 
00036                 {0, 1, 0, 0, 0, 1, 0}, 
00037                 {0, 1, 1, 0, 1, 0, 0}, 
00038                 {0, 1, 0, 0, 0, 0, 1}, 
00039                 {0, 0, 0, 0, 0, 0, 1}, 
00040                 {0, 1, 1, 1, 0, 1, 0}, 
00041                 {0, 0, 0, 0, 0, 0, 0}, 
00042                 {0, 1, 0, 0, 0, 0, 0}};
00043 
00044 int main()
00045 {
00046     while(1)
00047     {
00048         for(int i = 0; i < 7; i++)
00049         {
00050             //clear all pins
00051             myLeftPins[i] = 1;
00052             myRightPins[i] = 1;
00053         }        
00054         //Countdown loop
00055         for(int x = 99; x >= 0; x--)
00056         {
00057             //set the main counter
00058             for(int i = 0; i < 7; i++)
00059             {
00060                 //Left digit displays the value of x/10 ie the tens column
00061                 myLeftPins[i] = numb[x/10][i]; 
00062                 //Right digit displays the value of x%10 ie the units column
00063                 myRightPins[i] = numb[x%10][i];         
00064             }
00065             //1 second
00066             wait(1);
00067         }
00068     }
00069 }
00070 
00071