OX V1
Dependencies: mbed
Latrix.h@0:6182212860fb, 2016-12-05 (annotated)
- Committer:
- arthicha
- Date:
- Mon Dec 05 15:55:28 2016 +0000
- Revision:
- 0:6182212860fb
- Child:
- 1:6514e03fe62f
V1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
arthicha | 0:6182212860fb | 1 | #include "mbed.h" |
arthicha | 0:6182212860fb | 2 | |
arthicha | 0:6182212860fb | 3 | |
arthicha | 0:6182212860fb | 4 | Serial duino(PA_11, PA_12); |
arthicha | 0:6182212860fb | 5 | //Serial pc(USBTX, USBRX); |
arthicha | 0:6182212860fb | 6 | Timer timer; |
arthicha | 0:6182212860fb | 7 | |
arthicha | 0:6182212860fb | 8 | class Latrix |
arthicha | 0:6182212860fb | 9 | { |
arthicha | 0:6182212860fb | 10 | private: |
arthicha | 0:6182212860fb | 11 | |
arthicha | 0:6182212860fb | 12 | |
arthicha | 0:6182212860fb | 13 | uint8_t state_new; |
arthicha | 0:6182212860fb | 14 | uint8_t state_menu; |
arthicha | 0:6182212860fb | 15 | uint8_t state_show; |
arthicha | 0:6182212860fb | 16 | uint8_t state_exit; |
arthicha | 0:6182212860fb | 17 | uint8_t data; |
arthicha | 0:6182212860fb | 18 | int last[3]; |
arthicha | 0:6182212860fb | 19 | |
arthicha | 0:6182212860fb | 20 | int lis[30]; |
arthicha | 0:6182212860fb | 21 | |
arthicha | 0:6182212860fb | 22 | public: |
arthicha | 0:6182212860fb | 23 | void Latrix() |
arthicha | 0:6182212860fb | 24 | { |
arthicha | 0:6182212860fb | 25 | for(int i=0;i<30;i++) |
arthicha | 0:6182212860fb | 26 | { |
arthicha | 0:6182212860fb | 27 | lis[i] = i; |
arthicha | 0:6182212860fb | 28 | } |
arthicha | 0:6182212860fb | 29 | last[0] = 0; |
arthicha | 0:6182212860fb | 30 | last[1] = 0; |
arthicha | 0:6182212860fb | 31 | last[2] = 0; |
arthicha | 0:6182212860fb | 32 | } |
arthicha | 0:6182212860fb | 33 | |
arthicha | 0:6182212860fb | 34 | void Latrix::Chackmape(){ // |
arthicha | 0:6182212860fb | 35 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 36 | |
arthicha | 0:6182212860fb | 37 | |
arthicha | 0:6182212860fb | 38 | this->duino.putc(lis[23]); |
arthicha | 0:6182212860fb | 39 | |
arthicha | 0:6182212860fb | 40 | this->timer.reset(); |
arthicha | 0:6182212860fb | 41 | } |
arthicha | 0:6182212860fb | 42 | if (this->duino.readable()) |
arthicha | 0:6182212860fb | 43 | { |
arthicha | 0:6182212860fb | 44 | } |
arthicha | 0:6182212860fb | 45 | } |
arthicha | 0:6182212860fb | 46 | |
arthicha | 0:6182212860fb | 47 | void Latrix::Win(){ //ชนะ |
arthicha | 0:6182212860fb | 48 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 49 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 50 | this->duino.putc(this->lis[0]); |
arthicha | 0:6182212860fb | 51 | this->duino.putc(this->lis[1]); |
arthicha | 0:6182212860fb | 52 | this->duino.putc(this->lis[2]); |
arthicha | 0:6182212860fb | 53 | this->timer.reset(); |
arthicha | 0:6182212860fb | 54 | } |
arthicha | 0:6182212860fb | 55 | if (this->duino.readable()) |
arthicha | 0:6182212860fb | 56 | { |
arthicha | 0:6182212860fb | 57 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 58 | } |
arthicha | 0:6182212860fb | 59 | } |
arthicha | 0:6182212860fb | 60 | |
arthicha | 0:6182212860fb | 61 | void Latrix::Lose(){ //แพ้ |
arthicha | 0:6182212860fb | 62 | |
arthicha | 0:6182212860fb | 63 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 64 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 65 | this->duino.putc(this->lis[3]); |
arthicha | 0:6182212860fb | 66 | this->duino.putc(this->lis[4]); |
arthicha | 0:6182212860fb | 67 | this->duino.putc(this->lis[5]); |
arthicha | 0:6182212860fb | 68 | this->duino.putc(this->lis[6]); |
arthicha | 0:6182212860fb | 69 | this->timer.reset(); |
arthicha | 0:6182212860fb | 70 | } |
arthicha | 0:6182212860fb | 71 | if (this->duino.readable()) |
arthicha | 0:6182212860fb | 72 | { |
arthicha | 0:6182212860fb | 73 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 74 | } |
arthicha | 0:6182212860fb | 75 | |
arthicha | 0:6182212860fb | 76 | } |
arthicha | 0:6182212860fb | 77 | |
arthicha | 0:6182212860fb | 78 | |
arthicha | 0:6182212860fb | 79 | void Latrix::CountDown(int i){ //นับเวลา |
arthicha | 0:6182212860fb | 80 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 81 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 82 | this->duino.putc(this->lis[16-i]); |
arthicha | 0:6182212860fb | 83 | /*duino.putc(lis[7]); //9 |
arthicha | 0:6182212860fb | 84 | duino.putc(lis[8]); //8 |
arthicha | 0:6182212860fb | 85 | duino.putc(lis[9]); //7 |
arthicha | 0:6182212860fb | 86 | duino.putc(lis[10]);//6 |
arthicha | 0:6182212860fb | 87 | duino.putc(lis[11]);//5 |
arthicha | 0:6182212860fb | 88 | duino.putc(lis[12]);//4 |
arthicha | 0:6182212860fb | 89 | duino.putc(lis[13]);//3 |
arthicha | 0:6182212860fb | 90 | duino.putc(lis[14]);//2 |
arthicha | 0:6182212860fb | 91 | duino.putc(lis[15]);//1 |
arthicha | 0:6182212860fb | 92 | duino.putc(lis[16]);//0*/ |
arthicha | 0:6182212860fb | 93 | |
arthicha | 0:6182212860fb | 94 | this->timer.reset(); |
arthicha | 0:6182212860fb | 95 | } |
arthicha | 0:6182212860fb | 96 | if (this->duino.readable()){ |
arthicha | 0:6182212860fb | 97 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 98 | } |
arthicha | 0:6182212860fb | 99 | |
arthicha | 0:6182212860fb | 100 | } |
arthicha | 0:6182212860fb | 101 | |
arthicha | 0:6182212860fb | 102 | |
arthicha | 0:6182212860fb | 103 | void Correct(){ //เช็คถูก |
arthicha | 0:6182212860fb | 104 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 105 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 106 | this->duino.putc(lis[18]); |
arthicha | 0:6182212860fb | 107 | this->timer.reset(); |
arthicha | 0:6182212860fb | 108 | } |
arthicha | 0:6182212860fb | 109 | if (this->duino.readable()){ |
arthicha | 0:6182212860fb | 110 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 111 | } |
arthicha | 0:6182212860fb | 112 | |
arthicha | 0:6182212860fb | 113 | } |
arthicha | 0:6182212860fb | 114 | |
arthicha | 0:6182212860fb | 115 | void Latrix::Error(){ // |
arthicha | 0:6182212860fb | 116 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 117 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 118 | this->duino.putc(this->lis[19]); |
arthicha | 0:6182212860fb | 119 | this->timer.reset(); |
arthicha | 0:6182212860fb | 120 | } |
arthicha | 0:6182212860fb | 121 | if (this->duino.readable()){ |
arthicha | 0:6182212860fb | 122 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 123 | } |
arthicha | 0:6182212860fb | 124 | |
arthicha | 0:6182212860fb | 125 | } |
arthicha | 0:6182212860fb | 126 | void Latrix::MapComplete(){ //ลงค่าเสร็จ |
arthicha | 0:6182212860fb | 127 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 128 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 129 | |
arthicha | 0:6182212860fb | 130 | |
arthicha | 0:6182212860fb | 131 | this->duino.putc(this->lis[20]); |
arthicha | 0:6182212860fb | 132 | |
arthicha | 0:6182212860fb | 133 | |
arthicha | 0:6182212860fb | 134 | this->timer.reset(); |
arthicha | 0:6182212860fb | 135 | } |
arthicha | 0:6182212860fb | 136 | if (this->duino.readable()){ |
arthicha | 0:6182212860fb | 137 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 138 | } |
arthicha | 0:6182212860fb | 139 | |
arthicha | 0:6182212860fb | 140 | } |
arthicha | 0:6182212860fb | 141 | void Latrix::Wbox(){ //ตัวหลัก |
arthicha | 0:6182212860fb | 142 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 143 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 144 | |
arthicha | 0:6182212860fb | 145 | |
arthicha | 0:6182212860fb | 146 | this->duino.putc(this->lis[21]); |
arthicha | 0:6182212860fb | 147 | |
arthicha | 0:6182212860fb | 148 | |
arthicha | 0:6182212860fb | 149 | this->timer.reset(); |
arthicha | 0:6182212860fb | 150 | } |
arthicha | 0:6182212860fb | 151 | if (this->duino.readable()){ |
arthicha | 0:6182212860fb | 152 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 153 | } |
arthicha | 0:6182212860fb | 154 | } |
arthicha | 0:6182212860fb | 155 | |
arthicha | 0:6182212860fb | 156 | void Latrix::RotateComplete(){ //หมุน |
arthicha | 0:6182212860fb | 157 | if (this->timer.read() > 1) { |
arthicha | 0:6182212860fb | 158 | //pc.printf("Writing!\n\r"); |
arthicha | 0:6182212860fb | 159 | |
arthicha | 0:6182212860fb | 160 | |
arthicha | 0:6182212860fb | 161 | this->duino.putc(this->lis[22]); |
arthicha | 0:6182212860fb | 162 | |
arthicha | 0:6182212860fb | 163 | |
arthicha | 0:6182212860fb | 164 | this->timer.reset(); |
arthicha | 0:6182212860fb | 165 | } |
arthicha | 0:6182212860fb | 166 | if (this->duino.readable()){ |
arthicha | 0:6182212860fb | 167 | //pc.printf("recieving %c",duino.getc()); |
arthicha | 0:6182212860fb | 168 | } |
arthicha | 0:6182212860fb | 169 | |
arthicha | 0:6182212860fb | 170 | } |
arthicha | 0:6182212860fb | 171 | |
arthicha | 0:6182212860fb | 172 | |
arthicha | 0:6182212860fb | 173 | /*int main() { |
arthicha | 0:6182212860fb | 174 | |
arthicha | 0:6182212860fb | 175 | |
arthicha | 0:6182212860fb | 176 | |
arthicha | 0:6182212860fb | 177 | pc.baud(9600); |
arthicha | 0:6182212860fb | 178 | duino.baud(9600); |
arthicha | 0:6182212860fb | 179 | pc.printf("Starting...\n\r"); |
arthicha | 0:6182212860fb | 180 | |
arthicha | 0:6182212860fb | 181 | timer.start(); |
arthicha | 0:6182212860fb | 182 | while (1) { |
arthicha | 0:6182212860fb | 183 | if (btn == 9) |
arthicha | 0:6182212860fb | 184 | { |
arthicha | 0:6182212860fb | 185 | Win(); |
arthicha | 0:6182212860fb | 186 | |
arthicha | 0:6182212860fb | 187 | } |
arthicha | 0:6182212860fb | 188 | |
arthicha | 0:6182212860fb | 189 | if (btn == 9) |
arthicha | 0:6182212860fb | 190 | { |
arthicha | 0:6182212860fb | 191 | Lose(); |
arthicha | 0:6182212860fb | 192 | |
arthicha | 0:6182212860fb | 193 | } |
arthicha | 0:6182212860fb | 194 | if (btn == 0) |
arthicha | 0:6182212860fb | 195 | { |
arthicha | 0:6182212860fb | 196 | number(); |
arthicha | 0:6182212860fb | 197 | |
arthicha | 0:6182212860fb | 198 | } |
arthicha | 0:6182212860fb | 199 | |
arthicha | 0:6182212860fb | 200 | if (btn == 9) //True |
arthicha | 0:6182212860fb | 201 | { |
arthicha | 0:6182212860fb | 202 | correct(); |
arthicha | 0:6182212860fb | 203 | } |
arthicha | 0:6182212860fb | 204 | |
arthicha | 0:6182212860fb | 205 | if (btn == 9) //error |
arthicha | 0:6182212860fb | 206 | { |
arthicha | 0:6182212860fb | 207 | error(); |
arthicha | 0:6182212860fb | 208 | |
arthicha | 0:6182212860fb | 209 | } |
arthicha | 0:6182212860fb | 210 | if (btn == 9) |
arthicha | 0:6182212860fb | 211 | { |
arthicha | 0:6182212860fb | 212 | heart(); |
arthicha | 0:6182212860fb | 213 | } |
arthicha | 0:6182212860fb | 214 | |
arthicha | 0:6182212860fb | 215 | if (btn == 9) |
arthicha | 0:6182212860fb | 216 | { |
arthicha | 0:6182212860fb | 217 | woman(); |
arthicha | 0:6182212860fb | 218 | } |
arthicha | 0:6182212860fb | 219 | if (btn == 9) |
arthicha | 0:6182212860fb | 220 | { |
arthicha | 0:6182212860fb | 221 | von(); |
arthicha | 0:6182212860fb | 222 | } |
arthicha | 0:6182212860fb | 223 | |
arthicha | 0:6182212860fb | 224 | wait(0.4); |
arthicha | 0:6182212860fb | 225 | |
arthicha | 0:6182212860fb | 226 | if(state_show == 0) { |
arthicha | 0:6182212860fb | 227 | pc.printf("************\n"); |
arthicha | 0:6182212860fb | 228 | pc.printf(" Menu \n"); |
arthicha | 0:6182212860fb | 229 | pc.printf("1.Menu1\n"); |
arthicha | 0:6182212860fb | 230 | |
arthicha | 0:6182212860fb | 231 | state_show =1; |
arthicha | 0:6182212860fb | 232 | } |
arthicha | 0:6182212860fb | 233 | if(pc.readable()) { |
arthicha | 0:6182212860fb | 234 | data = pc.getc(); |
arthicha | 0:6182212860fb | 235 | pc.printf("\n"); |
arthicha | 0:6182212860fb | 236 | state_show =0; |
arthicha | 0:6182212860fb | 237 | state_exit =0; |
arthicha | 0:6182212860fb | 238 | switch(data) { |
arthicha | 0:6182212860fb | 239 | case '1': |
arthicha | 0:6182212860fb | 240 | do { |
arthicha | 0:6182212860fb | 241 | if(state_menu == 0) { |
arthicha | 0:6182212860fb | 242 | pc.printf("number 1-9\n"); |
arthicha | 0:6182212860fb | 243 | |
arthicha | 0:6182212860fb | 244 | state_menu = 1; |
arthicha | 0:6182212860fb | 245 | } |
arthicha | 0:6182212860fb | 246 | if(pc.readable()) |
arthicha | 0:6182212860fb | 247 | { |
arthicha | 0:6182212860fb | 248 | data = pc.getc(); |
arthicha | 0:6182212860fb | 249 | pc.printf("\n"); |
arthicha | 0:6182212860fb | 250 | state_menu=0; |
arthicha | 0:6182212860fb | 251 | switch(data) { |
arthicha | 0:6182212860fb | 252 | wait(0.5); |
arthicha | 0:6182212860fb | 253 | case '1': |
arthicha | 0:6182212860fb | 254 | duino.putc(lis[15]);//1 |
arthicha | 0:6182212860fb | 255 | break; |
arthicha | 0:6182212860fb | 256 | |
arthicha | 0:6182212860fb | 257 | case '2': |
arthicha | 0:6182212860fb | 258 | duino.putc(lis[14]);//2 |
arthicha | 0:6182212860fb | 259 | break; |
arthicha | 0:6182212860fb | 260 | case '3': |
arthicha | 0:6182212860fb | 261 | duino.putc(lis[13]);//3 |
arthicha | 0:6182212860fb | 262 | break; |
arthicha | 0:6182212860fb | 263 | case '4': |
arthicha | 0:6182212860fb | 264 | duino.putc(lis[12]);//4 |
arthicha | 0:6182212860fb | 265 | break; |
arthicha | 0:6182212860fb | 266 | case '5': |
arthicha | 0:6182212860fb | 267 | duino.putc(lis[11]);//5 |
arthicha | 0:6182212860fb | 268 | break; |
arthicha | 0:6182212860fb | 269 | case '6': |
arthicha | 0:6182212860fb | 270 | duino.putc(lis[10]);//6 |
arthicha | 0:6182212860fb | 271 | break; |
arthicha | 0:6182212860fb | 272 | case '7': |
arthicha | 0:6182212860fb | 273 | duino.putc(lis[9]);//7 |
arthicha | 0:6182212860fb | 274 | break; |
arthicha | 0:6182212860fb | 275 | case '8': |
arthicha | 0:6182212860fb | 276 | duino.putc(lis[8]);//8 |
arthicha | 0:6182212860fb | 277 | break; |
arthicha | 0:6182212860fb | 278 | case '9': |
arthicha | 0:6182212860fb | 279 | duino.putc(lis[7]);//9 |
arthicha | 0:6182212860fb | 280 | |
arthicha | 0:6182212860fb | 281 | break; |
arthicha | 0:6182212860fb | 282 | case 'H': |
arthicha | 0:6182212860fb | 283 | duino.putc(lis[17]);//happy |
arthicha | 0:6182212860fb | 284 | |
arthicha | 0:6182212860fb | 285 | break; |
arthicha | 0:6182212860fb | 286 | |
arthicha | 0:6182212860fb | 287 | |
arthicha | 0:6182212860fb | 288 | default: |
arthicha | 0:6182212860fb | 289 | pc.printf("plz select a or s\n"); |
arthicha | 0:6182212860fb | 290 | pc.printf("\n\n"); |
arthicha | 0:6182212860fb | 291 | break; |
arthicha | 0:6182212860fb | 292 | } |
arthicha | 0:6182212860fb | 293 | } |
arthicha | 0:6182212860fb | 294 | } while(state_exit ==0); |
arthicha | 0:6182212860fb | 295 | pc.printf("\n"); |
arthicha | 0:6182212860fb | 296 | break; |
arthicha | 0:6182212860fb | 297 | |
arthicha | 0:6182212860fb | 298 | |
arthicha | 0:6182212860fb | 299 | |
arthicha | 0:6182212860fb | 300 | } |
arthicha | 0:6182212860fb | 301 | } |
arthicha | 0:6182212860fb | 302 | } |
arthicha | 0:6182212860fb | 303 | }*/ |
arthicha | 0:6182212860fb | 304 |