I am working on a rock paper scissors game and I need some guidance for my code. Whenever I press any of the buttons, only the on_off light switches, the other lights (win, lose, tie, ...) stay off. Heres my code:
int lose = 12;
int tie = 11;
int win = 10;
int opponentRock = 9;
int opponentPaper = 8;
int opponentScissor = 7;
int buttonRock = 5;
int buttonPaper = 4;
int buttonScissor = 3;
int on_off = 13;
String myMove = "";
String opponentMove = "";
void setup() {
pinMode(on_off, OUTPUT);
pinMode(lose, OUTPUT);
pinMode(tie, OUTPUT);
pinMode(win, OUTPUT);
pinMode(opponentRock, OUTPUT);
pinMode(opponentPaper, OUTPUT);
pinMode(opponentScissor, OUTPUT);
pinMode(buttonRock, INPUT_PULLUP);
pinMode(buttonPaper, INPUT_PULLUP);
pinMode(buttonScissor, INPUT_PULLUP);
}
void loop(){
// checks if button pressed
if ((digitalRead(buttonRock) == LOW) || (digitalRead(buttonPaper) == LOW) || (digitalRead(buttonScissor) == LOW)) {
// turns on indicator
digitalWrite(on_off, HIGH);
// sets pressed button to your choice
if (digitalRead(buttonRock) == LOW){
myMove = "Rock";
}
if (digitalRead(buttonPaper) == LOW){
myMove = "Paper";
}
if (digitalRead(buttonScissor) == LOW){
myMove = "Scissor";
}
// chooses number 0-2
int rand_choice = (int)(random() * 3);
// sets number to rock, paper, or scissors
if (rand_choice == 0) {
opponentMove = "Rock";
digitalWrite(opponentRock, HIGH);
}
if (rand_choice == 1) {
opponentMove = "Paper";
digitalWrite(opponentPaper, HIGH);
}
if (rand_choice == 2) {
opponentMove = "Scissor";
digitalWrite(opponentScissor, HIGH);
}
// checks if won or lost or tied
if (myMove == opponentMove){
digitalWrite(tie, HIGH);
}
if (myMove == "Rock" && opponentMove == "Scissor") {
digitalWrite(win, HIGH);
}
if (myMove == "Paper" && opponentMove == "Rock") {
digitalWrite(win, HIGH);
}
if (myMove == "Scissor" && opponentMove == "Paper") {
digitalWrite(win, HIGH);
}
if (myMove == "Scissor" && opponentMove == "Rock") {
digitalWrite(lose, HIGH);
}
if (myMove == "Rock" && opponentMove == "Paper") {
digitalWrite(lose, HIGH);
}
if (myMove == "Paper" && opponentMove == "scissor") {
digitalWrite(lose, HIGH);
}
delay(1000);
// resets light statuses
digitalWrite(opponentRock, LOW);
digitalWrite(opponentPaper, LOW);
digitalWrite(opponentScissor, LOW);
digitalWrite(win, LOW);
digitalWrite(tie, LOW);
digitalWrite(lose, LOW);
// resets your choice and opponent's
myMove = "";
opponentMove = "";
// turns off indicator
digitalWrite(on_off, LOW);
}
}
Any help would be great. Btw I checked and tested the hardware and it looks like the code is the problem.