XBee Rock Paper Scissors

Dependencies:   TextLCD mbed

Committer:
JonathanYoung22193
Date:
Tue Oct 27 16:30:14 2015 +0000
Revision:
0:4e3027168064
hi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonathanYoung22193 0:4e3027168064 1 #include "mbed.h"
JonathanYoung22193 0:4e3027168064 2 #include "TextLCD.h"
JonathanYoung22193 0:4e3027168064 3
JonathanYoung22193 0:4e3027168064 4 Serial xbee(USBTX, USBRX);
JonathanYoung22193 0:4e3027168064 5
JonathanYoung22193 0:4e3027168064 6 TextLCD lcd(PTA13, PTD5, PTD0, PTD2, PTD3, PTD1, TextLCD::LCD16x2); // rs, e, d4-d7
JonathanYoung22193 0:4e3027168064 7
JonathanYoung22193 0:4e3027168064 8 DigitalIn enable1(PTA4);
JonathanYoung22193 0:4e3027168064 9 DigitalIn enable2(PTA5);
JonathanYoung22193 0:4e3027168064 10 DigitalIn enable3(PTC8);
JonathanYoung22193 0:4e3027168064 11 DigitalIn enable4(PTC9);
JonathanYoung22193 0:4e3027168064 12
JonathanYoung22193 0:4e3027168064 13 int main() {
JonathanYoung22193 0:4e3027168064 14 char move;
JonathanYoung22193 0:4e3027168064 15 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 16 lcd.printf("ROCK, PAPER, ");
JonathanYoung22193 0:4e3027168064 17 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 18 lcd.printf("SCISSORS ");
JonathanYoung22193 0:4e3027168064 19 while(1) {
JonathanYoung22193 0:4e3027168064 20 if (enable1){
JonathanYoung22193 0:4e3027168064 21 xbee.printf("R");
JonathanYoung22193 0:4e3027168064 22 wait(.05);
JonathanYoung22193 0:4e3027168064 23 if (xbee.readable()) {
JonathanYoung22193 0:4e3027168064 24 move = xbee.getc();
JonathanYoung22193 0:4e3027168064 25 if (move == 'R'){
JonathanYoung22193 0:4e3027168064 26 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 27 lcd.printf("ROCK VS ROCK ");
JonathanYoung22193 0:4e3027168064 28 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 29 lcd.printf("YOU TIED ");
JonathanYoung22193 0:4e3027168064 30 }
JonathanYoung22193 0:4e3027168064 31 if (move == 'P') {
JonathanYoung22193 0:4e3027168064 32 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 33 lcd.printf("ROCK VS PAPER ");
JonathanYoung22193 0:4e3027168064 34 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 35 lcd.printf("YOU LOST:( ");
JonathanYoung22193 0:4e3027168064 36 }
JonathanYoung22193 0:4e3027168064 37 if (move == 'S') {
JonathanYoung22193 0:4e3027168064 38 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 39 lcd.printf("ROCK VS SCISSORS");
JonathanYoung22193 0:4e3027168064 40 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 41 lcd.printf("YOU WON!:) ");
JonathanYoung22193 0:4e3027168064 42 }
JonathanYoung22193 0:4e3027168064 43 if (move == 'E') {
JonathanYoung22193 0:4e3027168064 44 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 45 lcd.printf("ROCK, PAPER, ");
JonathanYoung22193 0:4e3027168064 46 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 47 lcd.printf("SCISSORS ");
JonathanYoung22193 0:4e3027168064 48 }
JonathanYoung22193 0:4e3027168064 49 }
JonathanYoung22193 0:4e3027168064 50 }
JonathanYoung22193 0:4e3027168064 51 if (enable2){
JonathanYoung22193 0:4e3027168064 52 xbee.printf("P");
JonathanYoung22193 0:4e3027168064 53 wait(.05);
JonathanYoung22193 0:4e3027168064 54 if (xbee.readable()) {
JonathanYoung22193 0:4e3027168064 55 move = xbee.getc();
JonathanYoung22193 0:4e3027168064 56 if (move == 'R'){
JonathanYoung22193 0:4e3027168064 57 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 58 lcd.printf("PAPER VS ROCK ");
JonathanYoung22193 0:4e3027168064 59 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 60 lcd.printf("YOU WON!:) ");
JonathanYoung22193 0:4e3027168064 61 }
JonathanYoung22193 0:4e3027168064 62 if (move == 'P') {
JonathanYoung22193 0:4e3027168064 63 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 64 lcd.printf("PAPER VS PAPER ");
JonathanYoung22193 0:4e3027168064 65 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 66 lcd.printf("YOU TIED ");
JonathanYoung22193 0:4e3027168064 67 }
JonathanYoung22193 0:4e3027168064 68 if (move == 'S') {
JonathanYoung22193 0:4e3027168064 69 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 70 lcd.printf("PAPER V SCISSORS");
JonathanYoung22193 0:4e3027168064 71 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 72 lcd.printf("YOU LOST:( ");
JonathanYoung22193 0:4e3027168064 73 }
JonathanYoung22193 0:4e3027168064 74 if (move == 'E') {
JonathanYoung22193 0:4e3027168064 75 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 76 lcd.printf("ROCK, PAPER, ");
JonathanYoung22193 0:4e3027168064 77 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 78 lcd.printf("SCISSORS ");
JonathanYoung22193 0:4e3027168064 79 }
JonathanYoung22193 0:4e3027168064 80 }
JonathanYoung22193 0:4e3027168064 81 }
JonathanYoung22193 0:4e3027168064 82 if (enable3) {
JonathanYoung22193 0:4e3027168064 83 xbee.printf("S");
JonathanYoung22193 0:4e3027168064 84 wait(.05);
JonathanYoung22193 0:4e3027168064 85 if (xbee.readable()) {
JonathanYoung22193 0:4e3027168064 86 move = xbee.getc();
JonathanYoung22193 0:4e3027168064 87 if (move == 'R'){
JonathanYoung22193 0:4e3027168064 88 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 89 lcd.printf("SCISSORS VS ROCK");
JonathanYoung22193 0:4e3027168064 90 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 91 lcd.printf("YOU LOST:( ");
JonathanYoung22193 0:4e3027168064 92 }
JonathanYoung22193 0:4e3027168064 93 if (move == 'P') {
JonathanYoung22193 0:4e3027168064 94 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 95 lcd.printf("SCISSORS V PAPER");
JonathanYoung22193 0:4e3027168064 96 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 97 lcd.printf("YOU WON!:) ");
JonathanYoung22193 0:4e3027168064 98 }
JonathanYoung22193 0:4e3027168064 99 if (move == 'S') {
JonathanYoung22193 0:4e3027168064 100 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 101 lcd.printf("SCISS VS SCISS ");
JonathanYoung22193 0:4e3027168064 102 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 103 lcd.printf("YOU TIED ");
JonathanYoung22193 0:4e3027168064 104 }
JonathanYoung22193 0:4e3027168064 105 if (move == 'E') {
JonathanYoung22193 0:4e3027168064 106 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 107 lcd.printf("ROCK, PAPER, ");
JonathanYoung22193 0:4e3027168064 108 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 109 lcd.printf("SCISSORS ");
JonathanYoung22193 0:4e3027168064 110 }
JonathanYoung22193 0:4e3027168064 111 }
JonathanYoung22193 0:4e3027168064 112 }
JonathanYoung22193 0:4e3027168064 113 if (enable4) {
JonathanYoung22193 0:4e3027168064 114 xbee.printf("E");
JonathanYoung22193 0:4e3027168064 115 wait(.05);
JonathanYoung22193 0:4e3027168064 116 lcd.locate(0,0);
JonathanYoung22193 0:4e3027168064 117 lcd.printf("ROCK, PAPER, ");
JonathanYoung22193 0:4e3027168064 118 lcd.locate(0,1);
JonathanYoung22193 0:4e3027168064 119 lcd.printf("SCISSORS ");
JonathanYoung22193 0:4e3027168064 120 }
JonathanYoung22193 0:4e3027168064 121 }
JonathanYoung22193 0:4e3027168064 122 }