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