Andrew Bell / Mbed 2 deprecated lab2_2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 BusOut LED_Disp (p7,p11,p9,p8,p5,p6,p10,p12);
00003 InterruptIn plusbutton(p14); 
00004 InterruptIn minusbutton(p15);
00005 DigitalOut led1 (LED1);
00006 DigitalOut led2 (LED2);
00007  
00008 
00009 void DisplayNumber(int);
00010 void flip()
00011 {
00012     LED_Disp = !LED_Disp;    // toggle state of LED
00013 }
00014 
00015 int main()
00016 {
00017     plusbutton.rise(&flip);
00018     int i = 0;
00019     while(1)
00020     {
00021         if (plusbutton == 1)
00022         {
00023             led1 = 1;
00024             wait(0.5);
00025             i++;
00026             while(plusbutton)
00027             {
00028                 DisplayNumber(i);
00029             }
00030         }
00031         
00032         if (minusbutton == 1)
00033         {
00034             led2 = 1;
00035             wait(0.5);
00036             i--;
00037             while(minusbutton)
00038             {
00039                 DisplayNumber(i);
00040             }
00041         }
00042     }
00043 }
00044      
00045 
00046 void DisplayNumber(int num)
00047 {
00048     switch(num)    
00049     {
00050         case 0: 
00051         LED_Disp = ~0x3F;             // bit pattern for 0 
00052         break; 
00053             
00054         case 1:
00055         LED_Disp = ~0x06;
00056         break;
00057         
00058         case 2:
00059         LED_Disp = ~0x5B;
00060         break;  
00061         
00062         case 3:
00063         LED_Disp = ~0x4F;
00064         break;
00065         
00066         case 4:
00067         LED_Disp = ~0x66;
00068         break;
00069         
00070         case 5:
00071         LED_Disp = ~0x6D;
00072         break;
00073         
00074         case 6:
00075         LED_Disp = ~0x7C;
00076         break;
00077         
00078         case 7:
00079         LED_Disp = ~0x07;
00080         break;
00081         
00082         case 8:
00083         LED_Disp = ~0x7F;
00084         break; 
00085         
00086         case 9:
00087         LED_Disp = ~0x67;
00088         break;   
00089     }
00090 }
00091