Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 BusOut LED_Disp(p7,p11,p9,p8,p5,p6,p10,p12); 00004 00005 InterruptIn button_up(p14); //assign interrupt to 14 and 15 00006 InterruptIn button_down(p17); 00007 00008 int counter1; //global counter value 00009 00010 void Increment_up(void); //ISR to be assigned to button_up interrupt 00011 void Increment_down(void); 00012 void DisplayNumber(int); //function to display number on seven segment 00013 00014 int main() 00015 { 00016 button_up.rise(&Increment_up); //attach adress of ISR to interrupt 00017 button_down.rise(&Increment_down); 00018 00019 while(1) 00020 { 00021 wait(0.2); 00022 } 00023 } 00024 00025 // Interrupt function to increment counter 00026 void Increment_up(void) 00027 { 00028 counter1++; //increment counter 00029 00030 if(counter1 <0) // check for min value 00031 counter1 = 0; 00032 00033 if(counter1 >9) //check for max value 00034 counter1 = 9; 00035 00036 DisplayNumber(counter1); //display counter1 number on seven segment 00037 wait(0.3); //debounce timer 00038 00039 } 00040 00041 void Increment_down(void) 00042 { 00043 counter1--; 00044 if(counter1 <0) 00045 counter1 = 0; 00046 00047 if(counter1 >9) 00048 counter1 = 9; 00049 00050 DisplayNumber(counter1); 00051 wait(0.3); 00052 } 00053 00054 //funtion to display counter1 on seven segment 00055 void DisplayNumber(int num) 00056 { 00057 switch(num) 00058 { 00059 case 0: 00060 LED_Disp = ~0x3F; 00061 break; 00062 case 1: 00063 LED_Disp = ~0x06; 00064 break; 00065 case 2: 00066 LED_Disp = ~0x5B; 00067 break; 00068 case 3: 00069 LED_Disp = ~0x4F; 00070 break; 00071 case 4: 00072 LED_Disp = ~0x66; 00073 break; 00074 case 5: 00075 LED_Disp = ~0x6D; 00076 break; 00077 case 6: 00078 LED_Disp = ~0x7D; 00079 break; 00080 case 7: 00081 LED_Disp = ~0x07; 00082 break; 00083 case 8: 00084 LED_Disp = ~0x7F; 00085 break; 00086 case 9: 00087 LED_Disp = ~0x67; 00088 break; 00089 } 00090 } 00091 00092 00093 00094 00095
Generated on Thu Aug 18 2022 09:11:16 by
1.7.2