/* Great Day! * This is my version of Arduino Paper Rock Scissors using only an LCD 20x4 and a few buttons and resistors for additional hardware. * I created this game because I wanted to explore my creativity on the Arduino and I do not see that anyone else has produced this game for this platform. So it's a bit unique too. * I hope you enjoy playing it as much as I have had designing it. * I think you will find I copy / paste a lot of code from example codes. I'm not an Arduino Pro, more like an Amateurino. * * Versions * LCD_Paper_Rock_Scissors1 - 8/19/2018 - First iteration mostly trying to learn how to set up and use LCD and Buttons. Very buggy. Will not load. * LCD_Paper_Rock_Scissors2 - 9/21/2018 - Fleshed out most of the Flow Chart. Still full of bugs and will not load. * LCD_Paper_Rock_Scissors3 - 9/23/2018 - Flow Chart complete and updated. Program gets stuck on Arduino random number generator; turn of and it always picks Paper or Rock or Scissors but never a different choice. * LCD_Paper_Rock_Scissors4 - 9/27/2018 - Bug fixes and new Arduino random number generator. Now Arduino gets stuck on person's selection and forgets what person selected. Problems with Scoring. * LCD_Paper_Rock_Scissors5 - 10/3/2018 - Arduino can be set to hide its selections instead of always showing them (debug / cheat mode). Comments where to mod code for real play. "New Math" for Paper Rock Scissors, streamlines it, and it works. Added a fifth button for additional future game possibilities, which means had to recalculate the scale of buttons and their ranges. Installed everything in a capachino box during the month of November. * LCD_Paper_Rock_Scissors6 - 12/12/2018 - Better display instructions after having a couple people try it out. Some people tap buttons, some hold buttons. Arduino needs you to hold buttons for 1-3 seconds. Best game flow. * LCD_Paper_Rock_Scissors7 - 1/2/2019 - Improved graphics and give the user a choice of playing a Real game or with Cheat Mode on. * * David England * 8/19/2018 */ // Set up Libraries #include "Wire.h" // For I2C #include "LCD.h" // For LCD #include "LiquidCrystal_I2C.h" // Added library* //Set the pins on the I2C chip used for LCD connections //ADDR,EN,R/W,RS,D4,D5,D6,D7 LiquidCrystal_I2C lcd(0x3f,2,1,0,4,5,6,7); // 0x3F is the default I2C bus address of my backpack, yours might be different // declare variables int buTTon; //For reading buttons int PlayerScore; //USed to keep track of Player Score int ArduinoScore; //USed to keep track of Arduino Score int PlayerPRS; // Hold Strings: Paper, Rock, or Scissors for LCD printing int ArduinoPRS; // Hold Strings: Paper, Rock, or Scissors for LCD printing //int randNumber; // Used for creating random numbers void setup() { delay(500); // Set up LCD module and Splash Screen lcd.begin(20,4); // 20 x 4 LCD module lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL lcd.setBacklight(HIGH); lcd.clear(); lcd.setCursor(0,0); lcd.print(""); lcd.setCursor(0,1); lcd.print(""); lcd.setCursor(0,2); lcd.print(""); lcd.setCursor(0,3); lcd.print("PAPER ROCK SCISSORS!"); delay(1000); lcd.setCursor(0,0); lcd.print(""); lcd.setCursor(0,1); lcd.print(""); lcd.setCursor(0,2); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,3); lcd.print("[] O 8< "); delay(1000); lcd.setCursor(0,0); lcd.print(""); lcd.setCursor(0,1); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,2); lcd.print(" [] O 8= "); lcd.setCursor(0,3); lcd.print("1 Player vs Arduino "); delay(1000); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print(" [] O 8< "); lcd.setCursor(0,2); lcd.print("1 Player vs Arduino "); lcd.setCursor(0,3); lcd.print("David England, 2018 "); delay(5000); /* * Buttons for Paper Rock Scissors and maybe Others (Button & Resistor stack) * A set of push buttons and resistors that act as a voltage divider to feed a value to the analog pin. * That value represents the user value and takes care of anything strange like too many pins being selected. * Resistors 1k from + to analogue pin, a series of low Ohms (like 200 ea) from + to - with a button going to each joint, the other button pin to analog pin. * With 5 buttons you should get (check serial monitor) * B1 200 Ohms * B2 400 * B3 550 * B4 700 * B5 850 * NA 1023 * * Descision can be weighed by If/Then <300, <450, <600, <800, <900 ignore anything else. */ // initialize variables - give them some values ... of 0 buTTon = 0; //For reading buttons PlayerScore = 0; //USed to keep track of Player Score ArduinoScore = 0; //USed to keep track of Arduino Score PlayerPRS = 0; // Hold Strings: Paper, Rock, or Scissors for LCD printing ArduinoPRS = 0; // Hold Strings: Paper, Rock, or Scissors for LCD printing //randNumber = 0; // Used for creating random numbers randomSeed(analogRead(1)); // Good random numbers for Arduino selecting PRS } void loop() { //Ready to play statement lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Instructions"); lcd.setCursor(0,2); lcd.print("Press/HOLD GO Button"); lcd.setCursor(0,3); lcd.print("to advance."); delay(1000); NOPRESS1: buTTon = analogRead(A0); //Command used to read the Buttons //Did you press GO? //WAIT1 if (buTTon < 900){goto GO1;} delay(1000); goto NOPRESS1; GO1: lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER Covers ROCK"); lcd.setCursor(0,1); lcd.print("ROCK Breaks SCISSORS"); lcd.setCursor(0,2); lcd.print("SCISSORS Cuts PAPER"); lcd.setCursor(0,3); lcd.print("READY Press/HOLD GO!"); delay(1000); NOPRESS2: buTTon = analogRead(A0); //Command used to read the Buttons //Did you press GO? //WAIT1 if (buTTon < 900){goto MAIN_GAME;} delay(1000); goto NOPRESS2; //GO2: MAIN_GAME: //Arduino randomly selects PAPER or ROCK or SCISSORS lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Arduino Selects"); lcd.setCursor(0,2); lcd.print("[] O 8< [] O 8= [] O"); lcd.setCursor(0,3); lcd.print("8< [] O 8= [] O 8<"); delay(1000); lcd.setCursor(0,2); lcd.print("8< [] O 8= [] O 8<"); lcd.setCursor(0,3); lcd.print("O 8= [] O 8< [] O 8="); delay(1000); lcd.setCursor(0,2); lcd.print("O 8= [] O 8< [] O 8="); lcd.setCursor(0,3); lcd.print("[] O 8< [] O 8= [] O"); delay(1000); ArduinoPRS = random(1, 4); //ArduinoPRS = "PRS"; //ARDUINO picks a number 1 , 2, or 3 and that descision branches to PAPER, ROCK, or SCISSORS; if (ArduinoPRS == 1){goto ARDPAPER;} if (ArduinoPRS == 2){goto ARDROCK;} if (ArduinoPRS == 3){goto ARDSCISSORS;} //ArduinoPRS[]={"PAPER", "ROCK", "SCISSORS"}; ARDPAPER: lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Arduino Selects"); lcd.setCursor(0,2); lcd.print(ArduinoPRS); // To make Arduino's choice secret comment this line out // lcd.print(" OKAY "); // And remove this comment - for Paper, and Rock, and Scissors lcd.setCursor(0,3); lcd.print(" PAPER ! ! ! "); // To make Arduino's choice secret comment this line out // lcd.print(" READY ! ! ! "); // And remove this comment - for Paper, and Rock, and Scissors delay(3000); //if (ArduinoPRS = "PRS"){goto MAIN_GAME;} //This took care of an early bug but no longer needed //goto MAIN_GAME; goto PLAYERS_TURN;//Now it's the Players_turn ARDROCK: lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Arduino Selects"); lcd.setCursor(0,2); lcd.print(ArduinoPRS); // To make Arduino's choice secret comment this line out // lcd.print(" OKAY "); // And remove this comment - for Paper, and Rock, and Scissors lcd.setCursor(0,3); lcd.print(" ROCK ! ! ! "); // To make Arduino's choice secret comment this line out // lcd.print(" READY ! ! ! "); // And remove this comment - for Paper, and Rock, and Scissors delay(3000); //if (ArduinoPRS = "PRS"){goto MAIN_GAME;} //This took care of an early bug but no longer needed //goto MAIN_GAME; goto PLAYERS_TURN;//Now it's the Players_turn ARDSCISSORS: lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Arduino Selects"); // To make Arduino's choice secret comment this line out lcd.setCursor(0,2); lcd.print(ArduinoPRS); // lcd.print(" OKAY "); // And remove this comment - for Paper, and Rock, and Scissors lcd.setCursor(0,3); lcd.print(" SCISSORS ! ! ! "); // To make Arduino's choice secret comment this line out // lcd.print(" READY ! ! ! "); // And remove this comment - for Paper, and Rock, and Scissors delay(3000); //if (ArduinoPRS = "PRS"){goto MAIN_GAME;} //This took care of an early bug but no longer needed //goto MAIN_GAME; goto PLAYERS_TURN;//Now it's the Players_turn PLAYERS_TURN: lcd.clear(); lcd.setCursor(0,0); lcd.print("Please Select either"); lcd.setCursor(0,1); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,2); lcd.print("Press/HOLD GO when"); lcd.setCursor(0,3); lcd.print("Ready to shoot."); delay(1000); PlayerPRS = 0; NOPRESS3: buTTon = analogRead(A0); //Command used to read the Buttons //Did you press a button? //WAIT1 if (buTTon < 900){goto GO3;} //delay(1000); goto NOPRESS3; GO3: lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Player Selecting ..."); lcd.setCursor(0,2); lcd.print(". . . . . . . . . . "); lcd.setCursor(0,3); lcd.print(" . . . . . . . . . ."); delay(1000); lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Player Selecting ..."); lcd.setCursor(0,2); lcd.print(" . . . . . . . . . ."); lcd.setCursor(0,3); lcd.print(". . . . . . . . . . "); delay(1000); NOPRESS4: buTTon = analogRead(A0); //Command used to read the Buttons //What did you press? Did you press GO? //WAIT1 //delay(1000); if (buTTon > 0 && buTTon < 300){goto PLAYPAPER;} if (buTTon > 301 && buTTon < 450){goto PLAYROCK;} if (buTTon > 601 && buTTon < 800){goto PLAYROCK;} if (buTTon > 451 && buTTon < 600){goto PLAYSCISSORS;} if (buTTon > 801 && buTTon < 900){goto GO4;} //This is the GO-Shoot button if (buTTon > 901){goto GO3;} //This goes back to first selecting if NOPRESS above, scroll up if (PlayerPRS = 0){goto GO3;} if (PlayerPRS = 1){goto PLAYPAPER;} if (PlayerPRS = 2){goto PLAYROCK;} if (PlayerPRS = 3){goto PLAYSCISSORS;} // These last four lines used after plyer select PAPER ROCK SCISSORS but has pressed GO/SHOOT yet. Holds the descision or lets you change your descision. PLAYPAPER: PlayerPRS = 1; lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Player Selecting ..."); lcd.setCursor(0,2); lcd.print(" PAPER ! ! !"); lcd.setCursor(0,3); lcd.print("Press GO or reselect"); delay(1000); goto NOPRESS4; PLAYROCK: PlayerPRS = 2; lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Player Selecting ..."); lcd.setCursor(0,2); lcd.print(" ROCK ! ! !"); lcd.setCursor(0,3); lcd.print("Press GO or reselect"); delay(1000); goto NOPRESS4; PLAYSCISSORS: PlayerPRS = 3; lcd.clear(); lcd.setCursor(0,0); lcd.print("PAPER ROCK SCISSORS!"); lcd.setCursor(0,1); lcd.print("Player Selecting ..."); lcd.setCursor(0,2); lcd.print(" SCISSORS ! ! !"); lcd.setCursor(0,3); lcd.print("Press GO or reselect"); delay(1000); goto NOPRESS4; GO4: lcd.clear(); lcd.setCursor(0,0); if (PlayerPRS == 1){lcd.print("Player Chose Paper");} if (PlayerPRS == 2){lcd.print("Player Chose ROCK");} if (PlayerPRS == 3){lcd.print("Player Chose SCISSORS");} lcd.setCursor(0,1); if (ArduinoPRS == 1){lcd.print("Arduino Chose Paper");} if (ArduinoPRS == 2){lcd.print("Arduino Chose ROCK");} if (ArduinoPRS == 3){lcd.print("Arduino Chose SCISSORS");} lcd.setCursor(0,2); lcd.print("Player Score = ")+lcd.print(PlayerScore); lcd.setCursor(0,3); lcd.print("Arduino Score = ")+lcd.print(ArduinoScore); delay(5000); STRANGE_MATH: if (PlayerPRS == ArduinoPRS) goto TIE; //PlayerPRS == ArduinoPRS == "IT'S A TIE!" if (PlayerPRS == 1 && ArduinoPRS == 2){goto PLAYER_WINS;} //PlayerPRS == "PAPER" && ArduinoPRS == "ROCK" if (PlayerPRS == 2 && ArduinoPRS == 3){goto PLAYER_WINS;} //PlayerPRS == "ROCK" && ArduinoPRS == "SCISSORS" if (PlayerPRS == 3 && ArduinoPRS == 1){goto PLAYER_WINS;} //PlayerPRS == "SCISSORS" && ArduinoPRS == "PAPER" if (PlayerPRS == 1 && ArduinoPRS == 3){goto ARDUINO_WINS;} //PlayerPRS == "PAPER" && ArduinoPRS == "SCISSORS" if (PlayerPRS == 2 && ArduinoPRS == 1){goto ARDUINO_WINS;} //PlayerPRS == "ROCK" && ArduinoPRS == "PAPER" if (PlayerPRS == 3 && ArduinoPRS == 2){goto ARDUINO_WINS;} //PlayerPRS == "SCISSORS" && ArduinoPRS == "ROCK" //This should be no man's land and never print - Player hits GO but didn't select anything lcd.clear(); lcd.setCursor(0,0); lcd.print("OH NO ! ! !"); lcd.setCursor(0,1); lcd.print("Some thing went"); lcd.setCursor(0,2); lcd.print("Horribly wrong"); lcd.setCursor(0,3); lcd.print("This doesn't work"); delay(3000); goto PLAYERS_TURN; //Redo Players_turn TIE: //PRINT ITS A TIE ON LCD //NO SCORE lcd.clear(); lcd.setCursor(0,0); lcd.print("IT IS A TIE ! ! !"); lcd.setCursor(0,1); lcd.print("Player Score = ")+lcd.print(PlayerScore); lcd.setCursor(0,2); lcd.print("Arduino Score = ")+lcd.print(ArduinoScore); lcd.setCursor(0,3); lcd.print("Please Play Again"); delay(3000); goto FINAL_DESCISION; PLAYER_WINS: //PRINT PLAYER WINS ++PlayerScore; //PLAYER SCORE INCREASES lcd.clear(); lcd.setCursor(0,0); lcd.print("YOU WON "); lcd.setCursor(0,1); lcd.print("Player Score = ")+lcd.print(PlayerScore); lcd.setCursor(0,2); lcd.print("Arduino Score = ")+lcd.print(ArduinoScore); lcd.setCursor(0,3); lcd.print("Please Play Again"); delay(3000); goto FINAL_DESCISION; ARDUINO_WINS: //PRINT ARDUINO WINS ++ArduinoScore; //ARDUINO SCORE INCREASES lcd.clear(); lcd.setCursor(0,0); lcd.print("ARDUINO WON "); lcd.setCursor(0,1); lcd.print("Sorry, try again"); lcd.setCursor(0,2); lcd.print("Player Score = ")+lcd.print(PlayerScore); lcd.setCursor(0,3); lcd.print("Arduino Score = ")+lcd.print(ArduinoScore); delay(3000); goto FINAL_DESCISION; FINAL_DESCISION: //Go again? YES - Return to MAIN_GAME. NO - end but Ard don't end - so zombie mode: clear display and variables and count very high lcd.clear(); lcd.setCursor(0,0); lcd.print("That sure was fun"); lcd.setCursor(0,1); lcd.print("Play again? Press Go"); lcd.setCursor(0,2); lcd.print("Player Score = ")+lcd.print(PlayerScore); lcd.setCursor(0,3); lcd.print("Arduino Score = ")+lcd.print(ArduinoScore); delay(1000); NOPRESS6: buTTon = analogRead(A0); //Command used to read the Buttons //Go again? //If YES //Did you press GO? //WAIT if (buTTon < 900){goto MAIN_GAME;} delay(1000); goto NOPRESS6; //IF NO ZOMBIE MODE goto NOPRESS6 repeatedly } 340-345 536-540 670-673 780-782 885-888