Armin Klačar Josip Kvesić

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <cmath>
00003 int counter = 0;
00004 
00005 BusOut broj(dp2, dp1, dp28, dp6, dp5, dp27, dp26);
00006 BusOut cifra(dp23, dp24, dp25);
00007 DigitalOut decimal_point(dp4);
00008 
00009 BusIn columns(dp9,dp10,dp11,dp13);
00010 BusOut rows(dp16, dp15, dp17, dp18);
00011 
00012 int cifra_buffer[3] = {18, 18, 18};
00013 unsigned int segmenti[19] = {0x01, 0x4f, 0x12, 0x06, 0x4c,0x24, 0x20, 0x0f, 0x00, 0x04,0x08,0x60,0x31,0x42,0x30,0x38,0x48,0x36,0x7f};
00014 int pressed_button()
00015 {
00016     if(counter > 5) counter = 0;
00017     else
00018     {
00019         counter++;
00020         return -1;
00021     }
00022     int tipka[] = {1,2,3,10,4,5,6,11,7,8,9,12,16,0,17,13};
00023     for(int i = 0; i <= 3; i++)
00024     {
00025         rows = (1 << i);
00026         for(int j = 0; j <= 3; j++)
00027             if(columns == (1 << j))
00028                 return tipka[ i * 4 + j ];
00029     }
00030     return -1;
00031 }
00032 void display()
00033 {
00034     if(cifra_buffer[2] == 12)
00035     {
00036         cifra_buffer[0] = 18;
00037         cifra_buffer[1] = 18;
00038         cifra_buffer[2] = 18;
00039     }
00040     for(int i = 1; i <= 4; i = i * 2)
00041     {
00042         cifra = ~i;
00043         broj = segmenti[cifra_buffer[i/2]];
00044         decimal_point = 1;
00045         wait_ms(10);
00046     }
00047 }
00048 
00049 void buffer(int button)
00050 {
00051     if(button == -1) return;
00052 
00053     for(int i = 0; i <= 1; i++)
00054         cifra_buffer[i] = cifra_buffer[i + 1];
00055     cifra_buffer[2] = button;
00056 }
00057 int main()
00058 {
00059     bool stop=false;
00060     while(true)
00061     {
00062         if(!stop) buffer(pressed_button());
00063         display();
00064         if(columns) {stop=true;continue;}
00065         else stop=false;
00066     }
00067 
00068 }