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 EthernetInterface HTTPClient mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "uLCD_4DGL.h" 00003 #include "board.h" 00004 #include "rtos.h" 00005 #include "EthernetInterface.h" 00006 #include "HTTPClient.h" 00007 00008 uLCD_4DGL lcd(p28,p27,p30); // serial tx, serial rx, reset pin; 00009 00010 DigitalIn in0(p11); 00011 DigitalIn in1(p12); 00012 DigitalIn in2(p13); 00013 DigitalIn in3(p14); 00014 DigitalIn in4(p15); 00015 DigitalIn in5(p16); 00016 DigitalIn in6(p17); 00017 DigitalIn in7(p18); 00018 DigitalIn in8(p19); 00019 00020 Mutex stdio_mutex; 00021 00022 00023 00024 int player1=1; 00025 int player2=2; 00026 int turn =1; 00027 int printout = 0; 00028 00029 00030 void printBoard(int ** board) 00031 { 00032 lcd.cls(); 00033 lcd.line(0, 42 , 127, 42 , 0xFF0000); 00034 lcd.line(0, 84 , 127, 84 , 0xFF0000); 00035 lcd.line(42, 0 , 42, 127, 0xFF0000); 00036 lcd.line(84, 0, 84, 127, 0xFF0000); 00037 for(int i=0; i<3; i++) 00038 { 00039 for(int j=0; j<3; j++) 00040 { 00041 if(board[i][j] == 1) 00042 { 00043 lcd.line( j*42+2 , i*42 + 2 ,(j+1)*42-2 , (i+1)*42-2 , GREEN); 00044 lcd.line( j*42+2 , (i+1)*42 - 2 ,(j+1)*42-2 , (i)*42+2 , GREEN); 00045 } 00046 else if(board[i][j] == 2) 00047 { 00048 lcd.circle(42*j+21, 42*i+21, 19, BLUE); 00049 } 00050 } 00051 } 00052 } 00053 00054 HTTPClient http; 00055 char str[2048]; 00056 int main() { 00057 00058 EthernetInterface eth; 00059 eth.init(); //Use DHCP 00060 eth.connect(); 00061 printf("IP Address is %s\n", eth.getIPAddress()); 00062 printf("%d\n", sizeof(str)); 00063 int ret = http.get("http://ece4180mbedonlinegaming.azurewebsites.net/odata/TicTacToeGames(1)?$select=BoardState", str, 2048); 00064 printf("%d\n",ret); 00065 printf("Result: %s\n", str); 00066 /* 00067 in0.mode(PullUp); 00068 in1.mode(PullUp); 00069 in2.mode(PullUp); 00070 in3.mode(PullUp); 00071 in4.mode(PullUp); 00072 in5.mode(PullUp); 00073 in6.mode(PullUp); 00074 in7.mode(PullUp); 00075 in8.mode(PullUp); 00076 00077 Board board; 00078 int ** output = board.get_board(); 00079 printBoard(output); 00080 lcd.baudrate(3000000); 00081 00082 lcd.line(0, 42 , 127, 42 , 0xFF0000); 00083 lcd.line(0, 84 , 127, 84 , 0xFF0000); 00084 lcd.line(42, 0 , 42, 127, 0xFF0000); 00085 lcd.line(84, 0, 84, 127, 0xFF0000); 00086 00087 while (true) { 00088 if(!in0) 00089 printout = 1; 00090 else if(!in1) 00091 printout = 2; 00092 else if(!in2) 00093 printout = 3; 00094 else if(!in3) 00095 printout = 4; 00096 else if(!in4) 00097 printout = 5; 00098 else if(!in5) 00099 printout = 6; 00100 else if(!in6) 00101 printout = 7; 00102 else if(!in7) 00103 printout = 8; 00104 else if(!in8) 00105 printout = 9; 00106 else 00107 printout = 0; 00108 00109 00110 if(printout>0) 00111 { 00112 bool valid = board.updateBoard(turn, printout-1); 00113 00114 if(valid) 00115 { 00116 output = board.get_board(); 00117 printBoard(output); 00118 printout=0; 00119 int victory = board.check_victory(turn); 00120 if(victory ==1) 00121 { 00122 lcd.cls(); 00123 lcd.printf("player 1 win!"); 00124 return 0; 00125 } 00126 else if(victory == 2) 00127 { 00128 lcd.cls(); 00129 lcd.printf("player 2 win!"); 00130 return 0; 00131 } 00132 if(turn ==1) 00133 turn =2; 00134 else 00135 turn =1; 00136 } 00137 } 00138 Thread::wait(400); 00139 } 00140 */ 00141 00142 } 00143
Generated on Mon Jul 18 2022 03:38:34 by
1.7.2