tim010 tim010
/
L3_G1_Tim10_Z1
main.cpp@0:20276394d3d1, 2014-03-17 (annotated)
- Committer:
- tim010
- Date:
- Mon Mar 17 09:00:43 2014 +0000
- Revision:
- 0:20276394d3d1
L3_G1_T10-Z1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim010 | 0:20276394d3d1 | 1 | #include "mbed.h" |
tim010 | 0:20276394d3d1 | 2 | //by Enil Pajić@ETF, 16.03.2014 |
tim010 | 0:20276394d3d1 | 3 | BusOut bLEDS (dp23, dp24, dp25, dp26, dp27, dp5, dp6, dp28); //Led 0, 1, 2, 3, 4, 5, 6, 7 |
tim010 | 0:20276394d3d1 | 4 | DigitalOut dLEDS[8] = {dp23, dp24, dp25, dp26, dp27, dp5, dp6, dp28}; |
tim010 | 0:20276394d3d1 | 5 | |
tim010 | 0:20276394d3d1 | 6 | //BusOut bTASTER = (dp1, dp2); //dp1 = Taster1; dp2 = Taster2 |
tim010 | 0:20276394d3d1 | 7 | //DigitalOut dTASTER [2] = {dp1, dp2}; |
tim010 | 0:20276394d3d1 | 8 | |
tim010 | 0:20276394d3d1 | 9 | DigitalOut ENBL = dp14; |
tim010 | 0:20276394d3d1 | 10 | |
tim010 | 0:20276394d3d1 | 11 | //BusIn bKOL = (dp9, dp10, dp11, dp13); |
tim010 | 0:20276394d3d1 | 12 | //DigitalIn dKOL[4] = {dp9, dp10, dp11, dp13}; |
tim010 | 0:20276394d3d1 | 13 | |
tim010 | 0:20276394d3d1 | 14 | //BusOut bRED = (dp16, dp14, dp17, dp18); |
tim010 | 0:20276394d3d1 | 15 | //DigitalOut dRED[4] = {dp16, dp14, dp17, dp18}; |
tim010 | 0:20276394d3d1 | 16 | |
tim010 | 0:20276394d3d1 | 17 | BusOut bDISP (dp23, dp24, dp25); |
tim010 | 0:20276394d3d1 | 18 | BusOut dDISP[3] = {dp23, dp24, dp25}; |
tim010 | 0:20276394d3d1 | 19 | |
tim010 | 0:20276394d3d1 | 20 | BusOut bDIGIT(dp2, dp1, dp28, dp6, dp5, dp27, dp26); // (dp26, dp27, dp5, dp6, dp28, dp1, dp2); |
tim010 | 0:20276394d3d1 | 21 | DigitalOut dDIGIT[7] = {dp2, dp1, dp28, dp6, dp5, dp27, dp26}; |
tim010 | 0:20276394d3d1 | 22 | DigitalOut DECP (dp4); |
tim010 | 0:20276394d3d1 | 23 | //DigitalOut eA(dp26), eB(dp27), eC(dp5), eD(dp6), eE(dp28), eF(dp1), eG(dp2); |
tim010 | 0:20276394d3d1 | 24 | |
tim010 | 0:20276394d3d1 | 25 | typedef unsigned long T; |
tim010 | 0:20276394d3d1 | 26 | template <T N> |
tim010 | 0:20276394d3d1 | 27 | class eBIN |
tim010 | 0:20276394d3d1 | 28 | { |
tim010 | 0:20276394d3d1 | 29 | public: |
tim010 | 0:20276394d3d1 | 30 | enum {VAL = (N % 8) + (eBIN<N/8>::VAL << 1)}; |
tim010 | 0:20276394d3d1 | 31 | }; |
tim010 | 0:20276394d3d1 | 32 | template <> |
tim010 | 0:20276394d3d1 | 33 | class eBIN<0> |
tim010 | 0:20276394d3d1 | 34 | { |
tim010 | 0:20276394d3d1 | 35 | public: |
tim010 | 0:20276394d3d1 | 36 | enum {VAL = 0}; |
tim010 | 0:20276394d3d1 | 37 | }; |
tim010 | 0:20276394d3d1 | 38 | #define BIN(N) eBIN<0##N>::VAL |
tim010 | 0:20276394d3d1 | 39 | |
tim010 | 0:20276394d3d1 | 40 | enum Keys {N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, A, B, C, D, Star, Hash, None = -1}; |
tim010 | 0:20276394d3d1 | 41 | enum Diodes {D1 = 6, D2 = 5, D3 = 3}; |
tim010 | 0:20276394d3d1 | 42 | void Display (Keys Key, Diodes Diode, bool DisplayPoint) |
tim010 | 0:20276394d3d1 | 43 | { |
tim010 | 0:20276394d3d1 | 44 | if (Key == None) return; |
tim010 | 0:20276394d3d1 | 45 | bDISP = (int)Diode; |
tim010 | 0:20276394d3d1 | 46 | DECP = DisplayPoint ? 0 : 1; |
tim010 | 0:20276394d3d1 | 47 | switch (Key) |
tim010 | 0:20276394d3d1 | 48 | { |
tim010 | 0:20276394d3d1 | 49 | case N0: |
tim010 | 0:20276394d3d1 | 50 | bDIGIT = BIN(0000001); //1 |
tim010 | 0:20276394d3d1 | 51 | break; |
tim010 | 0:20276394d3d1 | 52 | case N1: |
tim010 | 0:20276394d3d1 | 53 | bDIGIT = BIN(1001111); //79 |
tim010 | 0:20276394d3d1 | 54 | break; |
tim010 | 0:20276394d3d1 | 55 | case N2: |
tim010 | 0:20276394d3d1 | 56 | bDIGIT = BIN(0010010); //18 |
tim010 | 0:20276394d3d1 | 57 | break; |
tim010 | 0:20276394d3d1 | 58 | case N3: |
tim010 | 0:20276394d3d1 | 59 | bDIGIT = BIN(0000110); //6 |
tim010 | 0:20276394d3d1 | 60 | break; |
tim010 | 0:20276394d3d1 | 61 | case N4: |
tim010 | 0:20276394d3d1 | 62 | bDIGIT = BIN(1001100); //76 |
tim010 | 0:20276394d3d1 | 63 | break; |
tim010 | 0:20276394d3d1 | 64 | case N5: |
tim010 | 0:20276394d3d1 | 65 | bDIGIT = BIN(0100100); //36 |
tim010 | 0:20276394d3d1 | 66 | break; |
tim010 | 0:20276394d3d1 | 67 | case N6: |
tim010 | 0:20276394d3d1 | 68 | bDIGIT = BIN(0100000); //32 |
tim010 | 0:20276394d3d1 | 69 | break; |
tim010 | 0:20276394d3d1 | 70 | case N7: |
tim010 | 0:20276394d3d1 | 71 | bDIGIT = BIN(0001111); //15 |
tim010 | 0:20276394d3d1 | 72 | break; |
tim010 | 0:20276394d3d1 | 73 | case N8: |
tim010 | 0:20276394d3d1 | 74 | bDIGIT = BIN(0000000); //0 |
tim010 | 0:20276394d3d1 | 75 | break; |
tim010 | 0:20276394d3d1 | 76 | case N9: |
tim010 | 0:20276394d3d1 | 77 | bDIGIT = BIN(0000100); //4 |
tim010 | 0:20276394d3d1 | 78 | break; |
tim010 | 0:20276394d3d1 | 79 | case A: |
tim010 | 0:20276394d3d1 | 80 | bDIGIT = BIN(0001000); //A //8 |
tim010 | 0:20276394d3d1 | 81 | break; |
tim010 | 0:20276394d3d1 | 82 | case B: |
tim010 | 0:20276394d3d1 | 83 | bDIGIT = BIN(1100000); //b //96 |
tim010 | 0:20276394d3d1 | 84 | break; |
tim010 | 0:20276394d3d1 | 85 | case C: |
tim010 | 0:20276394d3d1 | 86 | bDIGIT = BIN(1110010); //c //114 |
tim010 | 0:20276394d3d1 | 87 | break; |
tim010 | 0:20276394d3d1 | 88 | case D: |
tim010 | 0:20276394d3d1 | 89 | bDIGIT = BIN(0000010); //d //2 |
tim010 | 0:20276394d3d1 | 90 | break; |
tim010 | 0:20276394d3d1 | 91 | case Star: |
tim010 | 0:20276394d3d1 | 92 | //xD ovo je 'e' slovo. Za gornje 'o' slovo je 0011100, za 'u' je 1100011 a za donje 'o' je 1100010 |
tim010 | 0:20276394d3d1 | 93 | bDIGIT = BIN(0010000); // 16 //za 'P' = 0011000 |
tim010 | 0:20276394d3d1 | 94 | break; |
tim010 | 0:20276394d3d1 | 95 | case Hash: |
tim010 | 0:20276394d3d1 | 96 | bDIGIT = BIN(1001000); //slovo H kao HASH :D //72 |
tim010 | 0:20276394d3d1 | 97 | break; |
tim010 | 0:20276394d3d1 | 98 | case None: |
tim010 | 0:20276394d3d1 | 99 | bDIGIT = BIN(1111111); //127 |
tim010 | 0:20276394d3d1 | 100 | break; |
tim010 | 0:20276394d3d1 | 101 | } |
tim010 | 0:20276394d3d1 | 102 | |
tim010 | 0:20276394d3d1 | 103 | } |
tim010 | 0:20276394d3d1 | 104 | void DisplayKeys (Keys K1, Keys K2, Keys K3, unsigned int Point, int DelayMS = 10) |
tim010 | 0:20276394d3d1 | 105 | { |
tim010 | 0:20276394d3d1 | 106 | Display (K1, D1, Point == 1); |
tim010 | 0:20276394d3d1 | 107 | if (K1 != None) wait_ms (DelayMS); |
tim010 | 0:20276394d3d1 | 108 | Display (K2, D2, Point == 2); |
tim010 | 0:20276394d3d1 | 109 | if (K2 != None) wait_ms (DelayMS); |
tim010 | 0:20276394d3d1 | 110 | Display (K3, D3, Point == 3); |
tim010 | 0:20276394d3d1 | 111 | if (K3 != None) wait_ms (DelayMS); |
tim010 | 0:20276394d3d1 | 112 | } |
tim010 | 0:20276394d3d1 | 113 | char ReadKey () |
tim010 | 0:20276394d3d1 | 114 | { |
tim010 | 0:20276394d3d1 | 115 | static const int Keys[4] = {8, 4, 2, 1}; // {1, 2, 4, 8}; |
tim010 | 0:20276394d3d1 | 116 | static const char Chars[4][4] = { |
tim010 | 0:20276394d3d1 | 117 | {'1', '2', '3', 'A'}, |
tim010 | 0:20276394d3d1 | 118 | {'4', '5', '6', 'B'}, |
tim010 | 0:20276394d3d1 | 119 | {'7', '8', '9', 'C'}, |
tim010 | 0:20276394d3d1 | 120 | {'*', '0', '#', 'D'} |
tim010 | 0:20276394d3d1 | 121 | }; |
tim010 | 0:20276394d3d1 | 122 | for (int a = 0; a < 4; ++a) |
tim010 | 0:20276394d3d1 | 123 | { |
tim010 | 0:20276394d3d1 | 124 | //bRED = Keys[a]; |
tim010 | 0:20276394d3d1 | 125 | for (int b = 0; b < 4; ++b); |
tim010 | 0:20276394d3d1 | 126 | //if (bKOL == Keys[b]) |
tim010 | 0:20276394d3d1 | 127 | //return Chars [a][b]; |
tim010 | 0:20276394d3d1 | 128 | } |
tim010 | 0:20276394d3d1 | 129 | return '-'; |
tim010 | 0:20276394d3d1 | 130 | } |
tim010 | 0:20276394d3d1 | 131 | void TrciDesno (float Time = 0.75) |
tim010 | 0:20276394d3d1 | 132 | { |
tim010 | 0:20276394d3d1 | 133 | for (int a = 0; a < 8; ++a) |
tim010 | 0:20276394d3d1 | 134 | { |
tim010 | 0:20276394d3d1 | 135 | bLEDS = 255; // = 0; |
tim010 | 0:20276394d3d1 | 136 | dLEDS[a] = 0; // = 1; |
tim010 | 0:20276394d3d1 | 137 | wait (Time); |
tim010 | 0:20276394d3d1 | 138 | } |
tim010 | 0:20276394d3d1 | 139 | } |
tim010 | 0:20276394d3d1 | 140 | void TrciLijevo (float Time = 0.75) |
tim010 | 0:20276394d3d1 | 141 | { |
tim010 | 0:20276394d3d1 | 142 | for (int a = 7; a > -1; --a) |
tim010 | 0:20276394d3d1 | 143 | { |
tim010 | 0:20276394d3d1 | 144 | bLEDS = 255; // = 0; |
tim010 | 0:20276394d3d1 | 145 | dLEDS[a] = 0; // = 1; |
tim010 | 0:20276394d3d1 | 146 | wait (Time); |
tim010 | 0:20276394d3d1 | 147 | } |
tim010 | 0:20276394d3d1 | 148 | } |
tim010 | 0:20276394d3d1 | 149 | int main() //Main_Stoperica() |
tim010 | 0:20276394d3d1 | 150 | { |
tim010 | 0:20276394d3d1 | 151 | ENBL = 1; |
tim010 | 0:20276394d3d1 | 152 | for (int a = 0; a < 32; ++a) |
tim010 | 0:20276394d3d1 | 153 | DisplayKeys (N0, N0, N0, 2, 2); |
tim010 | 0:20276394d3d1 | 154 | //wait (2.0); |
tim010 | 0:20276394d3d1 | 155 | int ds = 1, sa = 0, ss = 0; |
tim010 | 0:20276394d3d1 | 156 | int Delay = 2; |
tim010 | 0:20276394d3d1 | 157 | bool Play = true; |
tim010 | 0:20276394d3d1 | 158 | while (7) |
tim010 | 0:20276394d3d1 | 159 | { |
tim010 | 0:20276394d3d1 | 160 | DisplayKeys ((Keys)sa, (Keys)ss, (Keys)ds, 2, 2); |
tim010 | 0:20276394d3d1 | 161 | if (Play) |
tim010 | 0:20276394d3d1 | 162 | { |
tim010 | 0:20276394d3d1 | 163 | if (++ds > 9) ss++, ds = 0; |
tim010 | 0:20276394d3d1 | 164 | if (ss > 9) sa++, ss = 0; |
tim010 | 0:20276394d3d1 | 165 | if (sa == 1 && ss == 2 && ds == 3) Play = false; |
tim010 | 0:20276394d3d1 | 166 | for (int a = 0; a < 16; ++a) |
tim010 | 0:20276394d3d1 | 167 | { |
tim010 | 0:20276394d3d1 | 168 | |
tim010 | 0:20276394d3d1 | 169 | DisplayKeys ((Keys)sa, (Keys)ss, (Keys)ds, 2, 2); |
tim010 | 0:20276394d3d1 | 170 | } |
tim010 | 0:20276394d3d1 | 171 | |
tim010 | 0:20276394d3d1 | 172 | //wait_ms (100 - 3 * Delay); |
tim010 | 0:20276394d3d1 | 173 | } |
tim010 | 0:20276394d3d1 | 174 | } |
tim010 | 0:20276394d3d1 | 175 | } |
tim010 | 0:20276394d3d1 | 176 | int Main_Calc() |
tim010 | 0:20276394d3d1 | 177 | { |
tim010 | 0:20276394d3d1 | 178 | const int Delay = 10; |
tim010 | 0:20276394d3d1 | 179 | DisplayKeys (None, None, N0, 0, 1); |
tim010 | 0:20276394d3d1 | 180 | int Digit = 0; |
tim010 | 0:20276394d3d1 | 181 | char Key = '-'; |
tim010 | 0:20276394d3d1 | 182 | int kA = None, kB = None, kC = N0; |
tim010 | 0:20276394d3d1 | 183 | bool Down = false; |
tim010 | 0:20276394d3d1 | 184 | while (7) |
tim010 | 0:20276394d3d1 | 185 | { |
tim010 | 0:20276394d3d1 | 186 | Key = ReadKey(); |
tim010 | 0:20276394d3d1 | 187 | if (Key != '-' && !Down) Down = true; |
tim010 | 0:20276394d3d1 | 188 | if (Key == '-') Down = false; |
tim010 | 0:20276394d3d1 | 189 | if (Down && (Key >= '0' && Key <= '9')) |
tim010 | 0:20276394d3d1 | 190 | { |
tim010 | 0:20276394d3d1 | 191 | if (Digit == 0) kC = (Keys)(Key - 48); |
tim010 | 0:20276394d3d1 | 192 | if (Digit == 1) kB = kC, kC = (Keys)(Key - 48); |
tim010 | 0:20276394d3d1 | 193 | if (Digit == 2) kA = kB, kB = kC, kC = (Keys)(Key - 48); |
tim010 | 0:20276394d3d1 | 194 | Digit++; |
tim010 | 0:20276394d3d1 | 195 | } |
tim010 | 0:20276394d3d1 | 196 | if (Down && (Key == 'C')) kA = None, kB = None, kC = N0, Digit = 0; |
tim010 | 0:20276394d3d1 | 197 | DisplayKeys ((Keys)kA, (Keys)kB, (Keys)kC, 0, Delay); |
tim010 | 0:20276394d3d1 | 198 | } |
tim010 | 0:20276394d3d1 | 199 | } |
tim010 | 0:20276394d3d1 | 200 | int MainL2 () |
tim010 | 0:20276394d3d1 | 201 | { |
tim010 | 0:20276394d3d1 | 202 | //int Z[] = {127, 191, 223, 239, 247, 251, 253, 254}; |
tim010 | 0:20276394d3d1 | 203 | ENBL = 0; |
tim010 | 0:20276394d3d1 | 204 | bLEDS = 255; |
tim010 | 0:20276394d3d1 | 205 | while (7) |
tim010 | 0:20276394d3d1 | 206 | { |
tim010 | 0:20276394d3d1 | 207 | char c = ReadKey(); |
tim010 | 0:20276394d3d1 | 208 | if (c > '0' && c < '9') dLEDS[int(c - 48 - 1)] = 0; |
tim010 | 0:20276394d3d1 | 209 | if (c == '0') bLEDS = 0; |
tim010 | 0:20276394d3d1 | 210 | if (c == '*') TrciLijevo(); |
tim010 | 0:20276394d3d1 | 211 | if (c == '#') TrciDesno(); |
tim010 | 0:20276394d3d1 | 212 | switch (c) |
tim010 | 0:20276394d3d1 | 213 | { |
tim010 | 0:20276394d3d1 | 214 | case 'A': |
tim010 | 0:20276394d3d1 | 215 | bLEDS = 255; //Samo ako efekat traje za vrijeme drzanja tastera |
tim010 | 0:20276394d3d1 | 216 | dLEDS[0] = dLEDS[1] = 0; |
tim010 | 0:20276394d3d1 | 217 | break; |
tim010 | 0:20276394d3d1 | 218 | case 'B': |
tim010 | 0:20276394d3d1 | 219 | bLEDS = 255; |
tim010 | 0:20276394d3d1 | 220 | dLEDS[2] = dLEDS[3] = 0; |
tim010 | 0:20276394d3d1 | 221 | break; |
tim010 | 0:20276394d3d1 | 222 | case 'C': |
tim010 | 0:20276394d3d1 | 223 | bLEDS = 255; |
tim010 | 0:20276394d3d1 | 224 | dLEDS[4] = dLEDS[5] = 0; |
tim010 | 0:20276394d3d1 | 225 | break; |
tim010 | 0:20276394d3d1 | 226 | case 'D': |
tim010 | 0:20276394d3d1 | 227 | bLEDS = 255; |
tim010 | 0:20276394d3d1 | 228 | dLEDS[6] = dLEDS[7] = 0; |
tim010 | 0:20276394d3d1 | 229 | break; |
tim010 | 0:20276394d3d1 | 230 | } |
tim010 | 0:20276394d3d1 | 231 | bLEDS = 255; // ako je efekat ukljucen samo za vrijeme drzanja tastera |
tim010 | 0:20276394d3d1 | 232 | //wait (0.25); |
tim010 | 0:20276394d3d1 | 233 | } |
tim010 | 0:20276394d3d1 | 234 | } |
tim010 | 0:20276394d3d1 | 235 | |
tim010 | 0:20276394d3d1 | 236 |