Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of app-board-RTOS-Threads by
main.cpp@5:36b6ce2faf88, 2015-10-20 (annotated)
- Committer:
- ethan_wireless
- Date:
- Tue Oct 20 17:24:08 2015 +0000
- Revision:
- 5:36b6ce2faf88
- Parent:
- 4:79863d2ea5a0
NA
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ethan_wireless | 5:36b6ce2faf88 | 1 | #include "mbed.h" |
ethan_wireless | 5:36b6ce2faf88 | 2 | #include "uLCD_4DGL.h" |
ethan_wireless | 5:36b6ce2faf88 | 3 | #include "SDFileSystem.h" |
ethan_wireless | 5:36b6ce2faf88 | 4 | #include "wave_player.h" |
ethan_wireless | 5:36b6ce2faf88 | 5 | #include "PinDetect.h" |
ethan_wireless | 5:36b6ce2faf88 | 6 | #include <mpr121.h> |
ethan_wireless | 5:36b6ce2faf88 | 7 | |
ethan_wireless | 5:36b6ce2faf88 | 8 | Serial pc(USBTX, USBRX); |
dreschpe | 1:1c6a9eaf55b5 | 9 | |
ethan_wireless | 5:36b6ce2faf88 | 10 | uLCD_4DGL lcd(p9, p10, p8); |
ethan_wireless | 5:36b6ce2faf88 | 11 | SDFileSystem sd(p5, p6, p7, p14, "sd"); //SD card |
dreschpe | 0:f6a57b843f79 | 12 | |
ethan_wireless | 5:36b6ce2faf88 | 13 | int key = 0; |
ethan_wireless | 5:36b6ce2faf88 | 14 | int *keyptr = &key; |
ethan_wireless | 5:36b6ce2faf88 | 15 | int turn = 0; |
ethan_wireless | 5:36b6ce2faf88 | 16 | int *turnptr = &turn; |
ethan_wireless | 5:36b6ce2faf88 | 17 | char won = 'n'; |
ethan_wireless | 5:36b6ce2faf88 | 18 | char start = 'n'; |
ethan_wireless | 5:36b6ce2faf88 | 19 | |
ethan_wireless | 5:36b6ce2faf88 | 20 | //Speaker |
ethan_wireless | 5:36b6ce2faf88 | 21 | AnalogOut DACout(p18); |
ethan_wireless | 5:36b6ce2faf88 | 22 | wave_player waver(&DACout); |
4180_1 | 4:79863d2ea5a0 | 23 | |
ethan_wireless | 5:36b6ce2faf88 | 24 | FILE *wave_file; |
ethan_wireless | 5:36b6ce2faf88 | 25 | void drawerase() |
ethan_wireless | 5:36b6ce2faf88 | 26 | { |
ethan_wireless | 5:36b6ce2faf88 | 27 | wave_file=fopen("/sd/erase16.wav","r"); |
ethan_wireless | 5:36b6ce2faf88 | 28 | waver.play(wave_file); |
ethan_wireless | 5:36b6ce2faf88 | 29 | fclose(wave_file); |
ethan_wireless | 5:36b6ce2faf88 | 30 | } |
ethan_wireless | 5:36b6ce2faf88 | 31 | void drawcircle() |
ethan_wireless | 5:36b6ce2faf88 | 32 | { |
ethan_wireless | 5:36b6ce2faf88 | 33 | wave_file=fopen("/sd/circle16.wav","r"); |
ethan_wireless | 5:36b6ce2faf88 | 34 | waver.play(wave_file); |
ethan_wireless | 5:36b6ce2faf88 | 35 | fclose(wave_file); |
ethan_wireless | 5:36b6ce2faf88 | 36 | } |
ethan_wireless | 5:36b6ce2faf88 | 37 | void drawcross() |
ethan_wireless | 5:36b6ce2faf88 | 38 | { |
ethan_wireless | 5:36b6ce2faf88 | 39 | wave_file=fopen("/sd/cross16.wav","r"); |
ethan_wireless | 5:36b6ce2faf88 | 40 | waver.play(wave_file); |
ethan_wireless | 5:36b6ce2faf88 | 41 | fclose(wave_file); |
ethan_wireless | 5:36b6ce2faf88 | 42 | } |
dreschpe | 0:f6a57b843f79 | 43 | |
ethan_wireless | 5:36b6ce2faf88 | 44 | //shift brite |
ethan_wireless | 5:36b6ce2faf88 | 45 | DigitalOut latch(p15); |
ethan_wireless | 5:36b6ce2faf88 | 46 | DigitalOut enable(p16); |
ethan_wireless | 5:36b6ce2faf88 | 47 | SPI spi(p11, p12, p13); |
ethan_wireless | 5:36b6ce2faf88 | 48 | void RGB_LED(int red, int green, int blue) |
dreschpe | 0:f6a57b843f79 | 49 | { |
ethan_wireless | 5:36b6ce2faf88 | 50 | unsigned int low_color=0; |
ethan_wireless | 5:36b6ce2faf88 | 51 | unsigned int high_color=0; |
ethan_wireless | 5:36b6ce2faf88 | 52 | high_color=(blue<<4)|((red&0x3C0)>>6); |
ethan_wireless | 5:36b6ce2faf88 | 53 | low_color=(((red&0x3F)<<10)|(green)); |
ethan_wireless | 5:36b6ce2faf88 | 54 | spi.write(high_color); |
ethan_wireless | 5:36b6ce2faf88 | 55 | spi.write(low_color); |
ethan_wireless | 5:36b6ce2faf88 | 56 | latch=1; |
ethan_wireless | 5:36b6ce2faf88 | 57 | latch=0; |
ethan_wireless | 5:36b6ce2faf88 | 58 | } |
ethan_wireless | 5:36b6ce2faf88 | 59 | void winningLED() |
ethan_wireless | 5:36b6ce2faf88 | 60 | { |
ethan_wireless | 5:36b6ce2faf88 | 61 | while(key!=4) { |
ethan_wireless | 5:36b6ce2faf88 | 62 | RGB_LED( 100, 0, 0); |
ethan_wireless | 5:36b6ce2faf88 | 63 | wait(.05); |
ethan_wireless | 5:36b6ce2faf88 | 64 | RGB_LED( 0, 100, 0); |
ethan_wireless | 5:36b6ce2faf88 | 65 | wait(.05); |
ethan_wireless | 5:36b6ce2faf88 | 66 | RGB_LED( 0, 0, 100); |
ethan_wireless | 5:36b6ce2faf88 | 67 | wait(.05); |
dreschpe | 0:f6a57b843f79 | 68 | } |
dreschpe | 0:f6a57b843f79 | 69 | } |
ethan_wireless | 5:36b6ce2faf88 | 70 | void tieLED() |
ethan_wireless | 5:36b6ce2faf88 | 71 | { |
ethan_wireless | 5:36b6ce2faf88 | 72 | RGB_LED(100, 100, 100); |
ethan_wireless | 5:36b6ce2faf88 | 73 | } |
dreschpe | 0:f6a57b843f79 | 74 | |
ethan_wireless | 5:36b6ce2faf88 | 75 | DigitalOut myled1(LED1); |
ethan_wireless | 5:36b6ce2faf88 | 76 | DigitalOut myled2(LED2); |
ethan_wireless | 5:36b6ce2faf88 | 77 | DigitalOut myled3(LED3); |
ethan_wireless | 5:36b6ce2faf88 | 78 | DigitalOut myled4(LED4); |
ethan_wireless | 5:36b6ce2faf88 | 79 | |
ethan_wireless | 5:36b6ce2faf88 | 80 | int pressed[12]={0}; |
ethan_wireless | 5:36b6ce2faf88 | 81 | |
ethan_wireless | 5:36b6ce2faf88 | 82 | //touch pad |
ethan_wireless | 5:36b6ce2faf88 | 83 | InterruptIn interrupt(p26); |
ethan_wireless | 5:36b6ce2faf88 | 84 | // Setup the i2c bus on pins 9 and 10 |
ethan_wireless | 5:36b6ce2faf88 | 85 | I2C i2c(p28, p27); |
ethan_wireless | 5:36b6ce2faf88 | 86 | // Setup the Mpr121: |
ethan_wireless | 5:36b6ce2faf88 | 87 | // constructor(i2c object, i2c address of the mpr121) |
ethan_wireless | 5:36b6ce2faf88 | 88 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
ethan_wireless | 5:36b6ce2faf88 | 89 | |
ethan_wireless | 5:36b6ce2faf88 | 90 | // Key hit/release interrupt routine |
ethan_wireless | 5:36b6ce2faf88 | 91 | void fallInterrupt() { |
ethan_wireless | 5:36b6ce2faf88 | 92 | int key_code=0; |
ethan_wireless | 5:36b6ce2faf88 | 93 | int i=0; |
ethan_wireless | 5:36b6ce2faf88 | 94 | int value=mpr121.read(0x00); |
ethan_wireless | 5:36b6ce2faf88 | 95 | value +=mpr121.read(0x01)<<8; |
ethan_wireless | 5:36b6ce2faf88 | 96 | // LED demo mod |
ethan_wireless | 5:36b6ce2faf88 | 97 | i=0; |
ethan_wireless | 5:36b6ce2faf88 | 98 | // puts key number out to LEDs for demo |
ethan_wireless | 5:36b6ce2faf88 | 99 | for (i=0; i<12; i++) { |
ethan_wireless | 5:36b6ce2faf88 | 100 | if (((value>>i)&0x01)==1) key_code=i+1; |
ethan_wireless | 5:36b6ce2faf88 | 101 | } |
ethan_wireless | 5:36b6ce2faf88 | 102 | myled4=key_code & 0x01; |
ethan_wireless | 5:36b6ce2faf88 | 103 | myled3=(key_code>>1) & 0x01; |
ethan_wireless | 5:36b6ce2faf88 | 104 | myled2=(key_code>>2) & 0x01; |
ethan_wireless | 5:36b6ce2faf88 | 105 | myled1=(key_code>>3) & 0x01; |
ethan_wireless | 5:36b6ce2faf88 | 106 | *keyptr = key_code; |
ethan_wireless | 5:36b6ce2faf88 | 107 | start = 'y'; |
ethan_wireless | 5:36b6ce2faf88 | 108 | } |
ethan_wireless | 5:36b6ce2faf88 | 109 | |
ethan_wireless | 5:36b6ce2faf88 | 110 | void drawBKG() |
ethan_wireless | 5:36b6ce2faf88 | 111 | { |
ethan_wireless | 5:36b6ce2faf88 | 112 | lcd.cls(); |
ethan_wireless | 5:36b6ce2faf88 | 113 | lcd.background_color(0x254542); |
ethan_wireless | 5:36b6ce2faf88 | 114 | drawerase(); |
ethan_wireless | 5:36b6ce2faf88 | 115 | lcd.line(2, 44, 126, 44, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 116 | lcd.line(2, 85, 126, 85, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 117 | lcd.line(44, 2, 44, 126, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 118 | lcd.line(85, 2, 85, 126, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 119 | } |
ethan_wireless | 5:36b6ce2faf88 | 120 | |
ethan_wireless | 5:36b6ce2faf88 | 121 | void winnercheck() |
dreschpe | 0:f6a57b843f79 | 122 | { |
ethan_wireless | 5:36b6ce2faf88 | 123 | if (pressed[3]==pressed[7]&&pressed[7]==pressed[11]&&pressed[3]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 124 | if(pressed[3]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 125 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 126 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 127 | } else if(pressed[3]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 128 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 129 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 130 | } |
ethan_wireless | 5:36b6ce2faf88 | 131 | lcd.line(23,23,107,23, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 132 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 133 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 134 | } else if (pressed[2]==pressed[6]&&pressed[6]==pressed[10]&&pressed[2]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 135 | if(pressed[2]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 136 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 137 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 138 | } else if(pressed[2]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 139 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 140 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 141 | } |
ethan_wireless | 5:36b6ce2faf88 | 142 | lcd.line(23,65,107,65, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 143 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 144 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 145 | } else if (pressed[1]==pressed[5]&&pressed[5]==pressed[9]&&pressed[1]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 146 | if(pressed[1]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 147 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 148 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 149 | } else if(pressed[1]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 150 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 151 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 152 | } |
ethan_wireless | 5:36b6ce2faf88 | 153 | lcd.line(23,107,107,107, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 154 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 155 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 156 | } else if (pressed[3]==pressed[2]&&pressed[2]==pressed[1]&&pressed[3]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 157 | if(pressed[3]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 158 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 159 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 160 | } else if(pressed[3]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 161 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 162 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 163 | } |
ethan_wireless | 5:36b6ce2faf88 | 164 | lcd.line(23,23,23,107, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 165 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 166 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 167 | } else if (pressed[7]==pressed[6]&&pressed[6]==pressed[5]&&pressed[7]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 168 | if(pressed[7]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 169 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 170 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 171 | } else if(pressed[7]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 172 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 173 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 174 | } |
ethan_wireless | 5:36b6ce2faf88 | 175 | lcd.line(65,23,65,107, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 176 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 177 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 178 | } else if (pressed[11]==pressed[10]&&pressed[10]==pressed[9]&&pressed[11]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 179 | if(pressed[11]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 180 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 181 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 182 | } else if(pressed[11]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 183 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 184 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 185 | } |
ethan_wireless | 5:36b6ce2faf88 | 186 | lcd.line(107,23,107,107, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 187 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 188 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 189 | } else if (pressed[3]==pressed[6]&&pressed[6]==pressed[9]&&pressed[3]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 190 | if(pressed[3]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 191 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 192 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 193 | } else if(pressed[3]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 194 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 195 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 196 | } |
ethan_wireless | 5:36b6ce2faf88 | 197 | lcd.line(23,23,107,107, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 198 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 199 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 200 | } else if (pressed[11]==pressed[6]&&pressed[6]==pressed[1]&&pressed[11]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 201 | if(pressed[11]==1) { |
ethan_wireless | 5:36b6ce2faf88 | 202 | lcd.locate(4,0); |
ethan_wireless | 5:36b6ce2faf88 | 203 | lcd.printf("circle wins"); |
ethan_wireless | 5:36b6ce2faf88 | 204 | } else if(pressed[11]==2) { |
ethan_wireless | 5:36b6ce2faf88 | 205 | lcd.locate(5,0); |
ethan_wireless | 5:36b6ce2faf88 | 206 | lcd.printf("cross wins"); |
ethan_wireless | 5:36b6ce2faf88 | 207 | } |
ethan_wireless | 5:36b6ce2faf88 | 208 | lcd.line(107,23,23,107, WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 209 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 210 | winningLED(); |
ethan_wireless | 5:36b6ce2faf88 | 211 | } else if (pressed[1]!=0 && pressed[2]!=0 &&pressed[3]!=0 && pressed[5]!=0 && pressed[6]!=0 && pressed[7]!=0 && pressed[9]!=0 && pressed[10]!=0 && pressed[11]!=0) { |
ethan_wireless | 5:36b6ce2faf88 | 212 | lcd.locate(7,0); |
ethan_wireless | 5:36b6ce2faf88 | 213 | lcd.printf("Tie"); |
ethan_wireless | 5:36b6ce2faf88 | 214 | won = 'w'; |
ethan_wireless | 5:36b6ce2faf88 | 215 | tieLED(); |
dreschpe | 0:f6a57b843f79 | 216 | } |
dreschpe | 0:f6a57b843f79 | 217 | } |
dreschpe | 0:f6a57b843f79 | 218 | |
ethan_wireless | 5:36b6ce2faf88 | 219 | void resetgame(){ |
ethan_wireless | 5:36b6ce2faf88 | 220 | drawBKG(); |
ethan_wireless | 5:36b6ce2faf88 | 221 | int i; |
ethan_wireless | 5:36b6ce2faf88 | 222 | for (i =0; i<=11;i++)pressed[i]=0; |
ethan_wireless | 5:36b6ce2faf88 | 223 | *turnptr = 0; |
ethan_wireless | 5:36b6ce2faf88 | 224 | won = 'n'; |
ethan_wireless | 5:36b6ce2faf88 | 225 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 226 | } |
ethan_wireless | 5:36b6ce2faf88 | 227 | |
ethan_wireless | 5:36b6ce2faf88 | 228 | int main() |
ethan_wireless | 5:36b6ce2faf88 | 229 | { |
ethan_wireless | 5:36b6ce2faf88 | 230 | spi.format(16,0); |
ethan_wireless | 5:36b6ce2faf88 | 231 | spi.frequency(500000); |
ethan_wireless | 5:36b6ce2faf88 | 232 | enable=0; |
ethan_wireless | 5:36b6ce2faf88 | 233 | latch=0; |
ethan_wireless | 5:36b6ce2faf88 | 234 | |
ethan_wireless | 5:36b6ce2faf88 | 235 | interrupt.fall(&fallInterrupt); |
ethan_wireless | 5:36b6ce2faf88 | 236 | interrupt.mode(PullUp); |
ethan_wireless | 5:36b6ce2faf88 | 237 | |
ethan_wireless | 5:36b6ce2faf88 | 238 | //welcome |
ethan_wireless | 5:36b6ce2faf88 | 239 | lcd.baudrate(3000000); |
ethan_wireless | 5:36b6ce2faf88 | 240 | lcd.text_width(2); |
ethan_wireless | 5:36b6ce2faf88 | 241 | lcd.text_height(2); |
ethan_wireless | 5:36b6ce2faf88 | 242 | lcd.locate(0,2); |
ethan_wireless | 5:36b6ce2faf88 | 243 | lcd.text_mode(TRANSPARENT); |
ethan_wireless | 5:36b6ce2faf88 | 244 | lcd.color(WHITE); |
ethan_wireless | 5:36b6ce2faf88 | 245 | lcd.printf(" Tic\n Tac\n Toe"); |
ethan_wireless | 5:36b6ce2faf88 | 246 | wait(3); |
ethan_wireless | 5:36b6ce2faf88 | 247 | lcd.cls(); |
ethan_wireless | 5:36b6ce2faf88 | 248 | lcd.color(RED); |
ethan_wireless | 5:36b6ce2faf88 | 249 | lcd.printf("Use lower area of the keypad to draw a circle or cross\n\nKey 3 to reset the game\n\nLED indicates next player\n\nPress any key to continue..."); |
ethan_wireless | 5:36b6ce2faf88 | 250 | while(start!='y') { |
ethan_wireless | 5:36b6ce2faf88 | 251 | wait(1); |
dreschpe | 1:1c6a9eaf55b5 | 252 | } |
ethan_wireless | 5:36b6ce2faf88 | 253 | |
ethan_wireless | 5:36b6ce2faf88 | 254 | lcd.cls(); |
ethan_wireless | 5:36b6ce2faf88 | 255 | lcd.background_color(0x254542); |
ethan_wireless | 5:36b6ce2faf88 | 256 | resetgame(); |
ethan_wireless | 5:36b6ce2faf88 | 257 | lcd.textbackground_color(0x254542); |
ethan_wireless | 5:36b6ce2faf88 | 258 | while (1) { |
ethan_wireless | 5:36b6ce2faf88 | 259 | if (key == 4) { |
ethan_wireless | 5:36b6ce2faf88 | 260 | resetgame(); |
ethan_wireless | 5:36b6ce2faf88 | 261 | } |
ethan_wireless | 5:36b6ce2faf88 | 262 | else if (pressed[key]==0 && won == 'n') { |
ethan_wireless | 5:36b6ce2faf88 | 263 | if (key == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 264 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 265 | lcd.circle(23, 107, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 266 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 267 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 268 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 269 | lcd.line(18, 100, 28, 114, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 270 | lcd.line(18, 114, 28, 100, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 271 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 272 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 273 | } |
ethan_wireless | 5:36b6ce2faf88 | 274 | pressed[1]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 275 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 276 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 277 | } else if (key == 2) { |
ethan_wireless | 5:36b6ce2faf88 | 278 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 279 | lcd.circle(23, 65, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 280 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 281 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 282 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 283 | lcd.line(18, 58, 28, 72, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 284 | lcd.line(18, 72, 28, 58, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 285 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 286 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 287 | } |
ethan_wireless | 5:36b6ce2faf88 | 288 | pressed[2]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 289 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 290 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 291 | } else if (key == 3) { |
ethan_wireless | 5:36b6ce2faf88 | 292 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 293 | lcd.circle(23, 23, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 294 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 295 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 296 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 297 | lcd.line(18, 16, 28, 30, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 298 | lcd.line(18, 30, 28, 16, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 299 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 300 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 301 | } |
ethan_wireless | 5:36b6ce2faf88 | 302 | pressed[3]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 303 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 304 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 305 | } else if (key == 5) { |
ethan_wireless | 5:36b6ce2faf88 | 306 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 307 | lcd.circle(65, 107, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 308 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 309 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 310 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 311 | lcd.line(60, 100, 70, 114, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 312 | lcd.line(60, 114, 70, 100, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 313 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 314 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 315 | } |
ethan_wireless | 5:36b6ce2faf88 | 316 | pressed[5]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 317 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 318 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 319 | } else if (key == 6) { |
ethan_wireless | 5:36b6ce2faf88 | 320 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 321 | lcd.circle(65, 65, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 322 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 323 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 324 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 325 | lcd.line(60, 58, 70, 72, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 326 | lcd.line(60, 72, 70, 58, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 327 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 328 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 329 | } |
ethan_wireless | 5:36b6ce2faf88 | 330 | pressed[6]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 331 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 332 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 333 | } else if (key == 7) { |
ethan_wireless | 5:36b6ce2faf88 | 334 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 335 | lcd.circle(65, 23, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 336 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 337 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 338 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 339 | lcd.line(60, 16, 70, 30, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 340 | lcd.line(60, 30, 70, 16, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 341 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 342 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 343 | } |
ethan_wireless | 5:36b6ce2faf88 | 344 | pressed[7]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 345 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 346 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 347 | } else if (key == 9) { |
ethan_wireless | 5:36b6ce2faf88 | 348 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 349 | lcd.circle(107, 107, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 350 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 351 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 352 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 353 | lcd.line(102, 100, 112, 114, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 354 | lcd.line(102, 114, 112, 100, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 355 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 356 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 357 | } |
ethan_wireless | 5:36b6ce2faf88 | 358 | pressed[9]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 359 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 360 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 361 | } else if (key == 10) { |
ethan_wireless | 5:36b6ce2faf88 | 362 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 363 | lcd.circle(107, 65, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 364 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 365 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 366 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 367 | lcd.line(102, 58, 112, 72, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 368 | lcd.line(102, 72, 112, 58, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 369 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 370 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 371 | } |
ethan_wireless | 5:36b6ce2faf88 | 372 | pressed[10]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 373 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 374 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 375 | } else if (key == 11) { |
ethan_wireless | 5:36b6ce2faf88 | 376 | if (turn == 0) { |
ethan_wireless | 5:36b6ce2faf88 | 377 | lcd.circle(107, 23, 10, RED); |
ethan_wireless | 5:36b6ce2faf88 | 378 | drawcircle(); |
ethan_wireless | 5:36b6ce2faf88 | 379 | RGB_LED(0,0,100); |
ethan_wireless | 5:36b6ce2faf88 | 380 | } else if(turn == 1) { |
ethan_wireless | 5:36b6ce2faf88 | 381 | lcd.line(102, 16, 112, 30, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 382 | lcd.line(102, 30, 112, 16, BLUE); |
ethan_wireless | 5:36b6ce2faf88 | 383 | drawcross(); |
ethan_wireless | 5:36b6ce2faf88 | 384 | RGB_LED(100,0,0); |
ethan_wireless | 5:36b6ce2faf88 | 385 | } |
ethan_wireless | 5:36b6ce2faf88 | 386 | pressed[11]=turn+1; |
ethan_wireless | 5:36b6ce2faf88 | 387 | *turnptr = (turn+1)%2; |
ethan_wireless | 5:36b6ce2faf88 | 388 | winnercheck(); |
ethan_wireless | 5:36b6ce2faf88 | 389 | } |
ethan_wireless | 5:36b6ce2faf88 | 390 | } |
4180_1 | 4:79863d2ea5a0 | 391 | } |
dreschpe | 1:1c6a9eaf55b5 | 392 | } |