Pajić Enil, Jakić Irma

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //LV8-Grupa1-Tim010-Z2
00002 #include "mbed.h"
00003 //By EnilP, 04.05.2014, ETF PAI
00004 BusIn bKOL(dp9, dp10, dp11, dp13);
00005 BusOut bRED(dp2, dp1, dp28, dp6); //(dp6, dp28, dp1, dp1); 
00006 Serial PC (USBTX, USBRX);
00007 Ticker T;
00008 Timer Dbnc;
00009 char ReadKey ()
00010     {
00011         static const int Keys[4] =  {1, 2, 4, 8}; // {8, 4, 2, 1};
00012         static const char Chars[4][4] = {
00013                                             {'1', '2', '3', 'A'},
00014                                             {'4', '5', '6', 'B'},
00015                                             {'7', '8', '9', 'C'},
00016                                             {'*', '0', '#', 'D'}
00017                                         };
00018         for (int a = 0; a < 4; ++a)
00019             {
00020                 bRED = Keys[a];
00021                 for (int b = 0; b < 4; ++b)
00022                     if (bKOL == Keys[b])
00023                         return Chars [a][b];
00024             }
00025         return '-';
00026     }
00027 void DoIt()
00028     {
00029         if (!PC.writeable()) return;
00030         char C = ReadKey();
00031         if (C == '-') return;
00032         if (Dbnc.read() > 0.2)
00033             {
00034                 if (C == '*')
00035                     PC.putc ('\n'); //\n = 10, \r = 13. {PC.putc (10); PC.putc (13);} ili PC.puts ("\r\n"); PC.printf ("\n");
00036                 else PC.putc (C);
00037             }
00038         Dbnc.reset();
00039     }
00040 int main ()
00041     {
00042         Dbnc.start();
00043         T.attach (&DoIt, 0.01); //Regulirati 0.001, 0.0001 | 0.1, 0.2
00044         while (7);
00045     }