XBee Rock Paper Scissors

Dependencies:   TextLCD mbed

Revision:
0:4e3027168064
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 27 16:30:14 2015 +0000
@@ -0,0 +1,122 @@
+#include "mbed.h"
+#include "TextLCD.h"
+
+Serial xbee(USBTX, USBRX);
+
+TextLCD lcd(PTA13, PTD5, PTD0, PTD2, PTD3, PTD1, TextLCD::LCD16x2); // rs, e, d4-d7
+
+DigitalIn enable1(PTA4);
+DigitalIn enable2(PTA5);
+DigitalIn enable3(PTC8);
+DigitalIn enable4(PTC9);
+
+int main() {
+    char move;
+    lcd.locate(0,0);
+    lcd.printf("ROCK, PAPER,    ");
+    lcd.locate(0,1);
+    lcd.printf("SCISSORS        ");
+    while(1) {
+        if (enable1){
+            xbee.printf("R");
+            wait(.05);
+            if (xbee.readable()) {
+                move = xbee.getc();
+                if (move == 'R'){
+                    lcd.locate(0,0);
+                    lcd.printf("ROCK VS ROCK    ");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU TIED        ");
+                    }
+                if (move == 'P') {
+                    lcd.locate(0,0);
+                    lcd.printf("ROCK VS PAPER   ");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU LOST:(      ");
+                    }
+                if (move == 'S') {
+                    lcd.locate(0,0);
+                    lcd.printf("ROCK VS SCISSORS");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU WON!:)      ");
+                    }
+                if (move == 'E') {
+                    lcd.locate(0,0);
+                    lcd.printf("ROCK, PAPER,    ");
+                    lcd.locate(0,1);
+                    lcd.printf("SCISSORS        ");
+                    }
+                }
+            }
+        if (enable2){
+            xbee.printf("P");
+            wait(.05);
+            if (xbee.readable()) {
+                move = xbee.getc();
+                if (move == 'R'){
+                    lcd.locate(0,0);
+                    lcd.printf("PAPER VS ROCK   ");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU WON!:)      ");
+                    }
+                if (move == 'P') {
+                    lcd.locate(0,0);
+                    lcd.printf("PAPER VS PAPER  ");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU TIED        ");
+                    }
+                if (move == 'S') {
+                    lcd.locate(0,0);
+                    lcd.printf("PAPER V SCISSORS");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU LOST:(      ");
+                    }
+                if (move == 'E') {
+                    lcd.locate(0,0);
+                    lcd.printf("ROCK, PAPER,    ");
+                    lcd.locate(0,1);
+                    lcd.printf("SCISSORS        ");
+                    }
+                }
+            }
+        if (enable3) {
+            xbee.printf("S");
+            wait(.05);
+            if (xbee.readable()) {
+                move = xbee.getc();
+                if (move == 'R'){
+                    lcd.locate(0,0);
+                    lcd.printf("SCISSORS VS ROCK");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU LOST:(      ");
+                    }
+                if (move == 'P') {
+                    lcd.locate(0,0);
+                    lcd.printf("SCISSORS V PAPER");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU WON!:)      ");
+                    }
+                if (move == 'S') {
+                    lcd.locate(0,0);
+                    lcd.printf("SCISS VS SCISS  ");
+                    lcd.locate(0,1);
+                    lcd.printf("YOU TIED        ");
+                    }
+                if (move == 'E') {
+                    lcd.locate(0,0);
+                    lcd.printf("ROCK, PAPER,    ");
+                    lcd.locate(0,1);
+                    lcd.printf("SCISSORS        ");
+                    }
+                }
+            }
+        if (enable4) {
+            xbee.printf("E");
+            wait(.05);
+            lcd.locate(0,0);
+            lcd.printf("ROCK, PAPER,    ");
+            lcd.locate(0,1);
+            lcd.printf("SCISSORS        ");
+            }
+        }
+    }
\ No newline at end of file