Mirhat Babić Granulo Eldar

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #define incompetence 10 
00004 
00005 BusOut segments(dp26, dp27, dp5, dp6, dp28, dp1, dp2);
00006 BusOut digit(dp23, dp24, dp26);
00007 DigitalOut point(dp24);
00008 
00009 BusIn columns(dp9, dp10, dp11, dp13);
00010 BusOut rows(dp16, dp15, dp17, dp18);
00011 
00012 int cifre[3] = {-1, -1, -1};
00013 int codes[10] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x078,0x0,0x10};
00014 int brojac = 0;
00015 
00016 
00017 int pressed_button() {
00018     
00019     int table[] = {1, 2, 3, -1, 4, 5, 6, -1, 
00020                     7, 8, 9, 12, -1, 0, -1, -1};
00021 
00022     for(int i = 0; i <= 3; i++) {
00023         rows = (1 << i); 
00024         for(int j = 0; j <= 3; j++)
00025             if(columns == (1 << j))
00026                 return table[ i * 4 + j ];
00027     }
00028 
00029     return -1;
00030 }
00031 
00032 void display() {
00033     /*for(digit = 1; digit <= 4; digit = digit * 2) { 
00034         segments = codes[ cifre[digit / 2] ];
00035         point = 1;
00036         wait_us(incompetence);
00037     }
00038     
00039 */
00040 
00041 
00042     digit = 3;
00043     segments = codes[ cifre[2]];
00044     wait_ms(2);
00045     
00046     digit = 7;
00047         
00048     digit = 5;
00049     segments = codes[ cifre[1]];
00050 
00051     wait_ms(2);
00052     
00053     digit = 7;    
00054 
00055     digit = 6;
00056     segments = codes[ cifre[0]];
00057     
00058         
00059     wait_ms(2);
00060     
00061     digit = 7;
00062         
00063     digit = 0;
00064     segments = 7;
00065     
00066     
00067 }
00068 
00069 void buffer(int button) {
00070     brojac = 0;
00071     for(int i = 0; i < 3; i++)
00072     if(cifre[i] == -1) brojac++;
00073     
00074     
00075     if(button >= 0 && button <= 9) {
00076         for(int i = brojac; i > 0; i--)
00077             cifre[i] = cifre[i - 1];
00078         cifre[0] = button;
00079     } else if(button == 12)
00080         for(int i = 0; i < 3; i++)
00081             cifre[i] = -1;
00082 }
00083 
00084 int main() {
00085     
00086     while(true) {
00087         
00088       
00089             buffer(pressed_button());
00090        // cifre[0] = pressed_button();
00091         display(); 
00092         
00093         
00094         
00095     }
00096 
00097    
00098 }