Hello,
I am currently a high school student and I have been stumped with a problem for the past few days. I am recreating the arduino game known as "Stop It" STOP IT GAME, and this game requires pins 2,3,4,5,6 for the led's to properly light up. When i change the led pins (I bolded the numbers down below) from 2,3,4,5,6 to 0,1,2,3,4, and shift the wires to pins 0,1,2,3,4 the game does not work anymore, the LED's flip out. Me and my engineering teacher can't figure out what is wrong. I am trying to run an lcd display LCD DISPLAY DIAGRAM to display the player score from the SERIAL MONITOR to the LCD, and the problem is that the LCD requires the same pins as the stop it game,and I can't seem to be able to change the order of pins that the stop it game OR the LCD require in order to function correctly, my engineering teacher read that the LCD requires pins 2-5 to work...:(, I was wondering if there is a way to run the program on two boards and hopefully the LCD will work in tandem with the stop it game....or is it not possible? My goal is to have an LCD display, the stop it game, and hopefully and buzzer all to be wired into one single arduino board, i am able to get the stop it game and LCD display to work independently on their own separate boards. If it is not possible could someone explain the way to run the boards together, we do not have the Bluetooth chip required to do this. Below I added the code that we wrote where we edited the stop it game, with the added LCD code in it. I also uploaded the original STOP IT GAME code. Any input would be greatly appreciated since we are completely stumped and don't know what to do. I am using SPARKFUN REDBOARD KIT.
Thanks for reading!
Post was too long to post original stop it game code. I put the code in a notepad so you do not have to create a new folders, just copy and paste
int Led1Pin = [b]0[/b]; //The pin of the first LED.
int Led2Pin = [b]1[/b]; //The pin of the second LED.
int Led3Pin = [b]2[/b]; //etc.
int Led4Pin = [b]3[/b];
int Led5Pin = [b]4[/b];
Stop it game with LCD coding:
#include <LiquidCrystal.h>
int Led1Pin = 2; //The pin of the first LED.
int Led2Pin = 3; //The pin of the second LED.
int Led3Pin = 4; //etc.
int Led4Pin = 5;
int Led5Pin = 6;
int ButtonPin = 8; //The pin of the button.
//The state of the button the last time we checked.
boolean old_val = LOW;
//Stores which LED is on.
int LightPosition = 0;
//How much time in between LED light changes.
int pause = 1000;
//What time it was when we last moved the light.
long lastMove = millis();
void setup()
{
pinMode(Led1Pin, OUTPUT);
pinMode(Led2Pin, OUTPUT);
pinMode(Led3Pin, OUTPUT);
pinMode(Led4Pin, OUTPUT);
pinMode(Led5Pin, OUTPUT);
pinMode(ButtonPin, INPUT);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
lcd.begin(16, 2);
Serial.begin(9600);
//Start a new game.
newGame();
}
void loop()
{
//Move the light.
if(millis() - lastMove >= pause)
{
lastMove = millis(); //Remember when we switched LED
LightPosition++; //increment the Light position.
if(LightPosition >= 6) LightPosition = 1;
move(LightPosition);//Update the light position.
}
//When the player presses the button...
if(digitalRead(ButtonPin) == HIGH && old_val == LOW)
{
//If the pressed it when the light was in the middle, speed up and continue.
if(LightPosition == 3)
{
digitalWrite(Led3Pin, LOW);
delay(50);
digitalWrite(Led3Pin, HIGH);
//Speed up the game.
if(pause > 700)
{
pause -= 100;
} else if (pause > 500)
{
pause -= 50;
} else if (pause > 300)
{
pause -= 25;
} else if (pause > 10)
{
pause -= 10;
} else if (pause > 1)
{
pause -= 1;
}
Serial.print("Score: ");
Serial.println(pause);
} else //If the pressed it at the wrong time, show their final score and start a new game.
{
//Game over
Serial.println("GAME OVER");
Serial.print("Final Score ");
Serial.println(pause);
//Blink the Led that the player stopped on.
for (int x = 0; x <= 10; x++)
{
if(digitalRead(LightPosition + 1) == LOW)
{
digitalWrite(LightPosition + 1, HIGH);
}
else
{
digitalWrite(LightPosition + 1, LOW);
}
delay(200);
}
//Show a LED bar based on how well the player did.
digitalWrite(Led1Pin,HIGH);
delay(500);
if (pause < 800)
{
digitalWrite(Led2Pin, HIGH);
delay(500);
}
if (pause < 600)
{
digitalWrite(Led3Pin, HIGH);
delay(500);
}
if (pause < 250)
{
digitalWrite(Led4Pin, HIGH);
delay(500);
}
if (pause < 100)
{
digitalWrite(Led5Pin, HIGH);
delay(500);
}
delay(3000);
newGame();
}
}
old_val = digitalRead(ButtonPin);
}
//Updates the light's position.
void move(int LightPosition)
{
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
lcd.begin(16, 2);
//Turn off all LEDs
for (int x = Led1Pin; x <= Led5Pin;x++)
{
digitalWrite(x, LOW);
}
//Turn on the LED
digitalWrite(LightPosition + 1, HIGH);
}
void newGame()
{
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
lcd.begin(16, 2);
LightPosition = 0;
pause = 1000;
lcd.println("New Game: Score 1000");
}
STOP IT GAME WITH LCD CODE.txt (3.47 KB)