![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
XBee Rock Paper Scissors
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 Serial xbee(USBTX, USBRX); 00005 00006 TextLCD lcd(PTA13, PTD5, PTD0, PTD2, PTD3, PTD1, TextLCD::LCD16x2); // rs, e, d4-d7 00007 00008 DigitalIn enable1(PTA4); 00009 DigitalIn enable2(PTA5); 00010 DigitalIn enable3(PTC8); 00011 DigitalIn enable4(PTC9); 00012 00013 int main() { 00014 char move; 00015 lcd.locate(0,0); 00016 lcd.printf("ROCK, PAPER, "); 00017 lcd.locate(0,1); 00018 lcd.printf("SCISSORS "); 00019 while(1) { 00020 if (enable1){ 00021 xbee.printf("R"); 00022 wait(.05); 00023 if (xbee.readable()) { 00024 move = xbee.getc(); 00025 if (move == 'R'){ 00026 lcd.locate(0,0); 00027 lcd.printf("ROCK VS ROCK "); 00028 lcd.locate(0,1); 00029 lcd.printf("YOU TIED "); 00030 } 00031 if (move == 'P') { 00032 lcd.locate(0,0); 00033 lcd.printf("ROCK VS PAPER "); 00034 lcd.locate(0,1); 00035 lcd.printf("YOU LOST:( "); 00036 } 00037 if (move == 'S') { 00038 lcd.locate(0,0); 00039 lcd.printf("ROCK VS SCISSORS"); 00040 lcd.locate(0,1); 00041 lcd.printf("YOU WON!:) "); 00042 } 00043 if (move == 'E') { 00044 lcd.locate(0,0); 00045 lcd.printf("ROCK, PAPER, "); 00046 lcd.locate(0,1); 00047 lcd.printf("SCISSORS "); 00048 } 00049 } 00050 } 00051 if (enable2){ 00052 xbee.printf("P"); 00053 wait(.05); 00054 if (xbee.readable()) { 00055 move = xbee.getc(); 00056 if (move == 'R'){ 00057 lcd.locate(0,0); 00058 lcd.printf("PAPER VS ROCK "); 00059 lcd.locate(0,1); 00060 lcd.printf("YOU WON!:) "); 00061 } 00062 if (move == 'P') { 00063 lcd.locate(0,0); 00064 lcd.printf("PAPER VS PAPER "); 00065 lcd.locate(0,1); 00066 lcd.printf("YOU TIED "); 00067 } 00068 if (move == 'S') { 00069 lcd.locate(0,0); 00070 lcd.printf("PAPER V SCISSORS"); 00071 lcd.locate(0,1); 00072 lcd.printf("YOU LOST:( "); 00073 } 00074 if (move == 'E') { 00075 lcd.locate(0,0); 00076 lcd.printf("ROCK, PAPER, "); 00077 lcd.locate(0,1); 00078 lcd.printf("SCISSORS "); 00079 } 00080 } 00081 } 00082 if (enable3) { 00083 xbee.printf("S"); 00084 wait(.05); 00085 if (xbee.readable()) { 00086 move = xbee.getc(); 00087 if (move == 'R'){ 00088 lcd.locate(0,0); 00089 lcd.printf("SCISSORS VS ROCK"); 00090 lcd.locate(0,1); 00091 lcd.printf("YOU LOST:( "); 00092 } 00093 if (move == 'P') { 00094 lcd.locate(0,0); 00095 lcd.printf("SCISSORS V PAPER"); 00096 lcd.locate(0,1); 00097 lcd.printf("YOU WON!:) "); 00098 } 00099 if (move == 'S') { 00100 lcd.locate(0,0); 00101 lcd.printf("SCISS VS SCISS "); 00102 lcd.locate(0,1); 00103 lcd.printf("YOU TIED "); 00104 } 00105 if (move == 'E') { 00106 lcd.locate(0,0); 00107 lcd.printf("ROCK, PAPER, "); 00108 lcd.locate(0,1); 00109 lcd.printf("SCISSORS "); 00110 } 00111 } 00112 } 00113 if (enable4) { 00114 xbee.printf("E"); 00115 wait(.05); 00116 lcd.locate(0,0); 00117 lcd.printf("ROCK, PAPER, "); 00118 lcd.locate(0,1); 00119 lcd.printf("SCISSORS "); 00120 } 00121 } 00122 }
Generated on Tue Jul 19 2022 15:50:11 by
![doxygen](doxygen.png)