![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Binary Calculator code and directories
Dependencies: 4DGL-uLCD-SE DebounceIn PinDetect mbed
Fork of uLCD144G2_demo by
Code for binary calculator which calculates AND OR NOR NAND and binary addition and subtraction
Demo video showing the calculator and the functions: /media/uploads/nickw0606/img_0261.mov
main.cpp@9:a7aa6c9f601a, 2015-03-13 (annotated)
- Committer:
- nickw0606
- Date:
- Fri Mar 13 07:00:42 2015 +0000
- Revision:
- 9:a7aa6c9f601a
- Parent:
- 8:31e63caf37e2
none;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 8:31e63caf37e2 | 1 | // uLCD-144-G2 demo program for uLCD-4GL LCD driver library |
4180_1 | 0:cfcf73272647 | 2 | // |
4180_1 | 0:cfcf73272647 | 3 | #include "mbed.h" |
4180_1 | 2:75727e89a717 | 4 | #include "uLCD_4DGL.h" |
nickw0606 | 9:a7aa6c9f601a | 5 | #include <math.h> |
nickw0606 | 9:a7aa6c9f601a | 6 | #include <cmath> |
nickw0606 | 9:a7aa6c9f601a | 7 | #include <bitset> |
nickw0606 | 9:a7aa6c9f601a | 8 | #include "PinDetect.h" |
nickw0606 | 9:a7aa6c9f601a | 9 | #include <cmath> |
nickw0606 | 9:a7aa6c9f601a | 10 | #include <string> |
4180_1 | 0:cfcf73272647 | 11 | |
nickw0606 | 9:a7aa6c9f601a | 12 | PinDetect pb1(p18); |
nickw0606 | 9:a7aa6c9f601a | 13 | PinDetect pb2(p17); |
nickw0606 | 9:a7aa6c9f601a | 14 | PinDetect pb3(p16); |
nickw0606 | 9:a7aa6c9f601a | 15 | PinDetect pb4(p15); |
nickw0606 | 9:a7aa6c9f601a | 16 | PinDetect pb5(p23); |
nickw0606 | 9:a7aa6c9f601a | 17 | PinDetect pb6(p24); |
nickw0606 | 9:a7aa6c9f601a | 18 | DigitalOut myled(LED1); |
nickw0606 | 9:a7aa6c9f601a | 19 | DigitalOut myled1(LED2); |
nickw0606 | 9:a7aa6c9f601a | 20 | DigitalOut myled2(LED3); |
nickw0606 | 9:a7aa6c9f601a | 21 | DigitalOut myled3(LED4); |
nickw0606 | 9:a7aa6c9f601a | 22 | uLCD_4DGL uLCD(p28,p27,p30); |
nickw0606 | 9:a7aa6c9f601a | 23 | DigitalIn dip1(p20); |
nickw0606 | 9:a7aa6c9f601a | 24 | DigitalIn dip2(p19); |
nickw0606 | 9:a7aa6c9f601a | 25 | DigitalIn dip3(p21); |
nickw0606 | 9:a7aa6c9f601a | 26 | DigitalIn dip4(p22); |
nickw0606 | 9:a7aa6c9f601a | 27 | DigitalIn dip5(p10); |
nickw0606 | 9:a7aa6c9f601a | 28 | DigitalIn dip6(p11); |
nickw0606 | 9:a7aa6c9f601a | 29 | DigitalIn dip7(p12); |
nickw0606 | 9:a7aa6c9f601a | 30 | DigitalIn dip8(p13); |
nickw0606 | 9:a7aa6c9f601a | 31 | Serial pc(USBTX, USBRX); // tx, rx |
nickw0606 | 9:a7aa6c9f601a | 32 | |
nickw0606 | 9:a7aa6c9f601a | 33 | int d1; |
nickw0606 | 9:a7aa6c9f601a | 34 | int d2; |
nickw0606 | 9:a7aa6c9f601a | 35 | int d3; |
nickw0606 | 9:a7aa6c9f601a | 36 | int d4; |
nickw0606 | 9:a7aa6c9f601a | 37 | int out; |
nickw0606 | 9:a7aa6c9f601a | 38 | void pb1_hit_callback (void) { |
nickw0606 | 9:a7aa6c9f601a | 39 | bitset<4> foo; |
nickw0606 | 9:a7aa6c9f601a | 40 | bitset<4> bar; |
nickw0606 | 9:a7aa6c9f601a | 41 | bitset<4> result; |
nickw0606 | 9:a7aa6c9f601a | 42 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 43 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 44 | foo.set(i,dip1); |
nickw0606 | 9:a7aa6c9f601a | 45 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 46 | foo.set(i,dip2); |
nickw0606 | 9:a7aa6c9f601a | 47 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 48 | foo.set(i,dip3); |
nickw0606 | 9:a7aa6c9f601a | 49 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 50 | foo.set(i,dip4); |
nickw0606 | 9:a7aa6c9f601a | 51 | } |
nickw0606 | 9:a7aa6c9f601a | 52 | } |
nickw0606 | 9:a7aa6c9f601a | 53 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 54 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 55 | bar.set(i,dip5); |
nickw0606 | 9:a7aa6c9f601a | 56 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 57 | bar.set(i,dip6); |
nickw0606 | 9:a7aa6c9f601a | 58 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 59 | bar.set(i,dip7); |
nickw0606 | 9:a7aa6c9f601a | 60 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 61 | bar.set(i,dip8); |
nickw0606 | 9:a7aa6c9f601a | 62 | } |
nickw0606 | 9:a7aa6c9f601a | 63 | } |
nickw0606 | 9:a7aa6c9f601a | 64 | uLCD.cls(); |
nickw0606 | 9:a7aa6c9f601a | 65 | uLCD.locate(0,0); |
nickw0606 | 9:a7aa6c9f601a | 66 | string fook = foo.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 67 | string book = bar.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 68 | result = foo&=bar; |
nickw0606 | 9:a7aa6c9f601a | 69 | string rook = result.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 70 | uLCD.printf("Calculation\n"); |
nickw0606 | 9:a7aa6c9f601a | 71 | uLCD.printf("%s AND %s\n\n",fook.c_str(),book.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 72 | uLCD.printf("Result\n"); |
nickw0606 | 9:a7aa6c9f601a | 73 | uLCD.printf("%s",rook.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 74 | //uLCD.printf("%d & %d - %d",foo.to_ulong(),bar.to_ulong(),result); |
nickw0606 | 9:a7aa6c9f601a | 75 | } |
nickw0606 | 9:a7aa6c9f601a | 76 | |
nickw0606 | 9:a7aa6c9f601a | 77 | void pb2_hit_callback (void) { |
nickw0606 | 9:a7aa6c9f601a | 78 | bitset<4> foo; |
nickw0606 | 9:a7aa6c9f601a | 79 | bitset<4> bar; |
nickw0606 | 9:a7aa6c9f601a | 80 | bitset<4> result; |
nickw0606 | 9:a7aa6c9f601a | 81 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 82 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 83 | foo.set(i,dip1); |
nickw0606 | 9:a7aa6c9f601a | 84 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 85 | foo.set(i,dip2); |
nickw0606 | 9:a7aa6c9f601a | 86 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 87 | foo.set(i,dip3); |
nickw0606 | 9:a7aa6c9f601a | 88 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 89 | foo.set(i,dip4); |
nickw0606 | 9:a7aa6c9f601a | 90 | } |
nickw0606 | 9:a7aa6c9f601a | 91 | } |
nickw0606 | 9:a7aa6c9f601a | 92 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 93 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 94 | bar.set(i,dip5); |
nickw0606 | 9:a7aa6c9f601a | 95 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 96 | bar.set(i,dip6); |
nickw0606 | 9:a7aa6c9f601a | 97 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 98 | bar.set(i,dip7); |
nickw0606 | 9:a7aa6c9f601a | 99 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 100 | bar.set(i,dip8); |
nickw0606 | 9:a7aa6c9f601a | 101 | } |
nickw0606 | 9:a7aa6c9f601a | 102 | } |
nickw0606 | 9:a7aa6c9f601a | 103 | uLCD.cls(); |
nickw0606 | 9:a7aa6c9f601a | 104 | uLCD.locate(0,0); |
nickw0606 | 9:a7aa6c9f601a | 105 | string fook = foo.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 106 | string book = bar.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 107 | result = foo|=bar; |
nickw0606 | 9:a7aa6c9f601a | 108 | string rook = result.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 109 | uLCD.printf("Calculation\n"); |
nickw0606 | 9:a7aa6c9f601a | 110 | uLCD.printf("%s OR %s\n\n",fook.c_str(),book.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 111 | uLCD.printf("Result\n"); |
nickw0606 | 9:a7aa6c9f601a | 112 | uLCD.printf("%s",rook.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 113 | } |
nickw0606 | 9:a7aa6c9f601a | 114 | |
nickw0606 | 9:a7aa6c9f601a | 115 | void pb3_hit_callback (void) { |
nickw0606 | 9:a7aa6c9f601a | 116 | bitset<4> foo; |
nickw0606 | 9:a7aa6c9f601a | 117 | bitset<4> bar; |
nickw0606 | 9:a7aa6c9f601a | 118 | bitset<4> result; |
nickw0606 | 9:a7aa6c9f601a | 119 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 120 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 121 | foo.set(i,dip1); |
nickw0606 | 9:a7aa6c9f601a | 122 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 123 | foo.set(i,dip2); |
nickw0606 | 9:a7aa6c9f601a | 124 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 125 | foo.set(i,dip3); |
nickw0606 | 9:a7aa6c9f601a | 126 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 127 | foo.set(i,dip4); |
nickw0606 | 9:a7aa6c9f601a | 128 | } |
nickw0606 | 9:a7aa6c9f601a | 129 | } |
nickw0606 | 9:a7aa6c9f601a | 130 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 131 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 132 | bar.set(i,dip5); |
nickw0606 | 9:a7aa6c9f601a | 133 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 134 | bar.set(i,dip6); |
nickw0606 | 9:a7aa6c9f601a | 135 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 136 | bar.set(i,dip7); |
nickw0606 | 9:a7aa6c9f601a | 137 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 138 | bar.set(i,dip8); |
nickw0606 | 9:a7aa6c9f601a | 139 | } |
nickw0606 | 9:a7aa6c9f601a | 140 | } |
nickw0606 | 9:a7aa6c9f601a | 141 | uLCD.cls(); |
nickw0606 | 9:a7aa6c9f601a | 142 | uLCD.locate(0,0); |
nickw0606 | 9:a7aa6c9f601a | 143 | string fook = foo.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 144 | string book = bar.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 145 | result = foo|=bar; |
nickw0606 | 9:a7aa6c9f601a | 146 | result = result.flip(); |
nickw0606 | 9:a7aa6c9f601a | 147 | string rook = result.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 148 | uLCD.printf("Calculation\n"); |
nickw0606 | 9:a7aa6c9f601a | 149 | uLCD.printf("%s NOR %s\n\n",fook.c_str(),book.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 150 | uLCD.printf("Result\n"); |
nickw0606 | 9:a7aa6c9f601a | 151 | uLCD.printf("%s",rook.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 152 | //uLCD.printf("%d",result.to_ulong()); |
nickw0606 | 9:a7aa6c9f601a | 153 | } |
nickw0606 | 9:a7aa6c9f601a | 154 | |
nickw0606 | 9:a7aa6c9f601a | 155 | void pb4_hit_callback (void) { |
nickw0606 | 9:a7aa6c9f601a | 156 | bitset<4> foo; |
nickw0606 | 9:a7aa6c9f601a | 157 | bitset<4> bar; |
nickw0606 | 9:a7aa6c9f601a | 158 | bitset<4> result; |
nickw0606 | 9:a7aa6c9f601a | 159 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 160 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 161 | foo.set(i,dip1); |
nickw0606 | 9:a7aa6c9f601a | 162 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 163 | foo.set(i,dip2); |
nickw0606 | 9:a7aa6c9f601a | 164 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 165 | foo.set(i,dip3); |
nickw0606 | 9:a7aa6c9f601a | 166 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 167 | foo.set(i,dip4); |
nickw0606 | 9:a7aa6c9f601a | 168 | } |
nickw0606 | 9:a7aa6c9f601a | 169 | } |
nickw0606 | 9:a7aa6c9f601a | 170 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 171 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 172 | bar.set(i,dip5); |
nickw0606 | 9:a7aa6c9f601a | 173 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 174 | bar.set(i,dip6); |
nickw0606 | 9:a7aa6c9f601a | 175 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 176 | bar.set(i,dip7); |
nickw0606 | 9:a7aa6c9f601a | 177 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 178 | bar.set(i,dip8); |
nickw0606 | 9:a7aa6c9f601a | 179 | } |
nickw0606 | 9:a7aa6c9f601a | 180 | } |
nickw0606 | 9:a7aa6c9f601a | 181 | uLCD.cls(); |
nickw0606 | 9:a7aa6c9f601a | 182 | uLCD.locate(0,0); |
nickw0606 | 9:a7aa6c9f601a | 183 | string fook = foo.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 184 | string book = bar.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 185 | result = foo&=bar; |
nickw0606 | 9:a7aa6c9f601a | 186 | result = result.flip(); |
nickw0606 | 9:a7aa6c9f601a | 187 | string rook = result.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 188 | uLCD.printf("Calculation\n"); |
nickw0606 | 9:a7aa6c9f601a | 189 | uLCD.printf("%s NAND %s\n\n",fook.c_str(),book.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 190 | uLCD.printf("Result\n"); |
nickw0606 | 9:a7aa6c9f601a | 191 | uLCD.printf("%s",rook.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 192 | } |
nickw0606 | 9:a7aa6c9f601a | 193 | |
nickw0606 | 9:a7aa6c9f601a | 194 | void pb5_hit_callback (void) { |
nickw0606 | 9:a7aa6c9f601a | 195 | bitset<4> foo; |
nickw0606 | 9:a7aa6c9f601a | 196 | bitset<4> bar; |
nickw0606 | 9:a7aa6c9f601a | 197 | bitset<4> result; |
nickw0606 | 9:a7aa6c9f601a | 198 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 199 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 200 | foo.set(i,dip1); |
nickw0606 | 9:a7aa6c9f601a | 201 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 202 | foo.set(i,dip2); |
nickw0606 | 9:a7aa6c9f601a | 203 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 204 | foo.set(i,dip3); |
nickw0606 | 9:a7aa6c9f601a | 205 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 206 | foo.set(i,dip4); |
nickw0606 | 9:a7aa6c9f601a | 207 | } |
nickw0606 | 9:a7aa6c9f601a | 208 | } |
nickw0606 | 9:a7aa6c9f601a | 209 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 210 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 211 | bar.set(i,dip5); |
nickw0606 | 9:a7aa6c9f601a | 212 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 213 | bar.set(i,dip6); |
nickw0606 | 9:a7aa6c9f601a | 214 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 215 | bar.set(i,dip7); |
nickw0606 | 9:a7aa6c9f601a | 216 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 217 | bar.set(i,dip8); |
nickw0606 | 9:a7aa6c9f601a | 218 | } |
nickw0606 | 9:a7aa6c9f601a | 219 | } |
nickw0606 | 9:a7aa6c9f601a | 220 | uLCD.cls(); |
nickw0606 | 9:a7aa6c9f601a | 221 | uLCD.locate(0,0); |
nickw0606 | 9:a7aa6c9f601a | 222 | int n1 = (int) foo.to_ulong(); |
nickw0606 | 9:a7aa6c9f601a | 223 | int n2 = (int) bar.to_ulong(); |
nickw0606 | 9:a7aa6c9f601a | 224 | string fook = foo.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 225 | string book = bar.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 226 | uLCD.printf("Calculation\n"); |
nickw0606 | 9:a7aa6c9f601a | 227 | uLCD.printf("%s + %s\n\n",fook.c_str(),book.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 228 | uLCD.printf("Result\n"); |
nickw0606 | 9:a7aa6c9f601a | 229 | bitset<8> res(n1+n2); |
nickw0606 | 9:a7aa6c9f601a | 230 | string rook = res.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 231 | uLCD.printf("%s",rook.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 232 | |
nickw0606 | 9:a7aa6c9f601a | 233 | } |
nickw0606 | 9:a7aa6c9f601a | 234 | |
nickw0606 | 9:a7aa6c9f601a | 235 | void pb6_hit_callback (void) { |
nickw0606 | 9:a7aa6c9f601a | 236 | bitset<4> foo; |
nickw0606 | 9:a7aa6c9f601a | 237 | bitset<4> bar; |
nickw0606 | 9:a7aa6c9f601a | 238 | bitset<4> result; |
nickw0606 | 9:a7aa6c9f601a | 239 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 240 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 241 | foo.set(i,dip1); |
nickw0606 | 9:a7aa6c9f601a | 242 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 243 | foo.set(i,dip2); |
nickw0606 | 9:a7aa6c9f601a | 244 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 245 | foo.set(i,dip3); |
nickw0606 | 9:a7aa6c9f601a | 246 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 247 | foo.set(i,dip4); |
nickw0606 | 9:a7aa6c9f601a | 248 | } |
nickw0606 | 9:a7aa6c9f601a | 249 | } |
nickw0606 | 9:a7aa6c9f601a | 250 | for(int i = 0; i < 4;i++){ |
nickw0606 | 9:a7aa6c9f601a | 251 | if(i == 0){ |
nickw0606 | 9:a7aa6c9f601a | 252 | bar.set(i,dip5); |
nickw0606 | 9:a7aa6c9f601a | 253 | }else if(i == 1){ |
nickw0606 | 9:a7aa6c9f601a | 254 | bar.set(i,dip6); |
nickw0606 | 9:a7aa6c9f601a | 255 | }else if(i == 2){ |
nickw0606 | 9:a7aa6c9f601a | 256 | bar.set(i,dip7); |
nickw0606 | 9:a7aa6c9f601a | 257 | }else if(i == 3){ |
nickw0606 | 9:a7aa6c9f601a | 258 | bar.set(i,dip8); |
nickw0606 | 9:a7aa6c9f601a | 259 | } |
nickw0606 | 9:a7aa6c9f601a | 260 | } |
nickw0606 | 9:a7aa6c9f601a | 261 | uLCD.cls(); |
nickw0606 | 9:a7aa6c9f601a | 262 | uLCD.locate(0,0); |
nickw0606 | 9:a7aa6c9f601a | 263 | int n1 = (int) foo.to_ulong(); |
nickw0606 | 9:a7aa6c9f601a | 264 | int n2 = (int) bar.to_ulong(); |
nickw0606 | 9:a7aa6c9f601a | 265 | string fook = foo.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 266 | string book = bar.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 267 | string rook = result.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 268 | uLCD.printf("Calculation\n"); |
nickw0606 | 9:a7aa6c9f601a | 269 | uLCD.printf("%s - %s\n\n",fook.c_str(),book.c_str()); |
nickw0606 | 9:a7aa6c9f601a | 270 | uLCD.printf("Result\n"); |
nickw0606 | 9:a7aa6c9f601a | 271 | //bitset<8> res(abs (n1-n2)); |
nickw0606 | 9:a7aa6c9f601a | 272 | //string rok = res.to_string<char,string::traits_type,string::allocator_type>(); |
nickw0606 | 9:a7aa6c9f601a | 273 | uLCD.printf("%d",abs (n1-n2)); |
nickw0606 | 9:a7aa6c9f601a | 274 | |
nickw0606 | 9:a7aa6c9f601a | 275 | } |
4180_1 | 0:cfcf73272647 | 276 | |
4180_1 | 2:75727e89a717 | 277 | int main() |
4180_1 | 2:75727e89a717 | 278 | { |
nickw0606 | 9:a7aa6c9f601a | 279 | dip1.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 280 | dip2.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 281 | dip3.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 282 | dip4.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 283 | dip5.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 284 | dip6.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 285 | dip7.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 286 | dip8.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 287 | pb1.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 288 | pb2.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 289 | pb3.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 290 | pb4.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 291 | pb5.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 292 | pb6.mode(PullUp); |
nickw0606 | 9:a7aa6c9f601a | 293 | pb1.attach_deasserted(&pb1_hit_callback); |
nickw0606 | 9:a7aa6c9f601a | 294 | // Start sampling pb input using interrupts |
nickw0606 | 9:a7aa6c9f601a | 295 | pb1.setSampleFrequency(); |
nickw0606 | 9:a7aa6c9f601a | 296 | pb2.attach_deasserted(&pb2_hit_callback); |
nickw0606 | 9:a7aa6c9f601a | 297 | pb2.setSampleFrequency(); |
nickw0606 | 9:a7aa6c9f601a | 298 | pb3.attach_deasserted(&pb3_hit_callback); |
nickw0606 | 9:a7aa6c9f601a | 299 | pb3.setSampleFrequency(); |
nickw0606 | 9:a7aa6c9f601a | 300 | pb4.attach_deasserted(&pb4_hit_callback); |
nickw0606 | 9:a7aa6c9f601a | 301 | pb4.setSampleFrequency(); |
nickw0606 | 9:a7aa6c9f601a | 302 | pb5.attach_deasserted(&pb5_hit_callback); |
nickw0606 | 9:a7aa6c9f601a | 303 | pb5.setSampleFrequency(); |
nickw0606 | 9:a7aa6c9f601a | 304 | pb6.attach_deasserted(&pb6_hit_callback); |
nickw0606 | 9:a7aa6c9f601a | 305 | pb6.setSampleFrequency(); |
nickw0606 | 9:a7aa6c9f601a | 306 | wait(1); |
nickw0606 | 9:a7aa6c9f601a | 307 | while(1) { |
nickw0606 | 9:a7aa6c9f601a | 308 | |
nickw0606 | 9:a7aa6c9f601a | 309 | |
nickw0606 | 9:a7aa6c9f601a | 310 | |
nickw0606 | 9:a7aa6c9f601a | 311 | |
nickw0606 | 9:a7aa6c9f601a | 312 | } |
4180_1 | 7:7bd7397ab89f | 313 | |
4180_1 | 6:f752accd632c | 314 | } |