Running lcd display with stop it game??

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.

:smiley: :grinning: Thanks for reading! :smiley: :grinning:

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 :slight_smile:

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)

Welcome to the Forum. Please read this post:

How to use this forum - please read.

Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Hi,

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](http://fritzing.org/media/fritzing-repo/projects/l/lcd-display-pcb-for-arduino-mounting-arduino-requi/images/LCD W%3AArduino PCB Layout.png) 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.
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.

Sorry mate, had to spread it out to make it easier to read.

Using pins 0 and 1 are not recommended as they are the tx and rx pins used to program the arduino.
You can change the pins used by the LCD, or you can use pins 6,7,8,9,10 as your LED pin outputs.

Hope it helps..Tom... :slight_smile:

sorry about the cramming of info, we've tried multiple different slots but still doesn't do any good...

bdraub:
we've tried multiple different slots

Do you mean pins?
Also you should not have the instantiation of th LCD class inside the setup function because it will go out of scope so I am not sure that the code you posted would compile.

Hi,
Can you post a circuit diagram of your project,
How have you got your button wired, is it between the input and 5V or input and gnd?
If you leave the LCD connected as you have shown and use the sketch as shown but;
Connect your LEDs to 6, 7, 8, 9 and 10
Connect your button to pin 13.
Edit your sketch to;

int Led1Pin = 6; //The pin of the first LED.
int Led2Pin = 7; //The pin of the second LED.
int Led3Pin = 8; //etc.
int Led4Pin = 9;
int Led5Pin = 10;

int ButtonPin = 13; //The pin of the button.

You have these lines repeated through the sketch, take them out, you only need the first line before the void setup and the second line inside the void setup. They are the setup instructions for the LCD and only need running once on powerup.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  lcd.begin(16, 2);

Does it work, if not what isn't it doing?

Did you write the sketch or get it from another source?

Tom.... :slight_smile:

when I change LED pins to 6-10 and my code, led's do not light up correctly
my code has pins 6-10 listed, but when I plug the pins into 2-6 it still works somehow....??

Hi,

Can you post a picture of your project so we can see the layout of your components.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a fritzy diagram.
The picture is probably more important at this stage.

Thanks.. Tom.... :slight_smile:

Also post your latest code so we can see if you have done the changes we told you about correctly.
Do not modify the code in the first post.

The LED's light up in the correct order. but when we press the button on any of the 5 leds the game ends because for some reason no led is the correct one...

int Led1Pin = 6; //The pin of the first LED.
int Led2Pin = 7; //The pin of the second LED.
int Led3Pin = 8; //etc.
int Led4Pin = 9;
int Led5Pin = 10;

int ButtonPin = 13; //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);
  
  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 >= 10) LightPosition = 5;
    
    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 == 4)
    {
      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)
{
 //Turn off all LEDs
for (int x = Led1Pin; x <= Led5Pin;x++)
{
  digitalWrite(x, LOW);
}

//Turn on the LED
digitalWrite(LightPosition + 1, HIGH);
}

void newGame()
{
  LightPosition = 0;
  pause = 1000;
  Serial.println("New Game: Score 1000");
}

So new update, the code below is the new code that we wrote, the LCD display lights up all the way bright, the display flickers like it wants to say a message, but it doesn't display the player score. anyone know why this happens?? :frowning:

int Led1Pin = 6; //The pin of the first LED.
int Led2Pin = 7; //The pin of the second LED.
int Led3Pin = 8; //etc.
int Led4Pin = 9;
int Led5Pin = 10;

int ButtonPin = 13; //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();
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16, 2);
  pinMode(Led1Pin, OUTPUT);
  pinMode(Led2Pin, OUTPUT);
  pinMode(Led3Pin, OUTPUT);
  pinMode(Led4Pin, OUTPUT);
  pinMode(Led5Pin, OUTPUT);
  pinMode(ButtonPin, INPUT);
  
  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 >= 10) LightPosition = 5;
    
    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 == 7)
    {
      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)
{
 //Turn off all LEDs
for (int x = Led1Pin; x <= Led5Pin;x++)
{
  digitalWrite(x, LOW);
}

//Turn on the LED
digitalWrite(LightPosition + 1, HIGH);
}

void newGame()
{
  LightPosition = 0;
  pause = 1000;
  Serial.println("New Game: Score 1000");
}

since it isn't displaying correctly, I have to change Serial.print and Serial.println to lcd.print or just Serial.print.

Hi,
Look here to see what commands to use to print to the LCD Display.

Tom... :slight_smile:

I appreciate the link, but we already tried all. Here is a video of what happens with the LCD, it flickers like it wants to print something but it wont. Everything is wired correctly and no wires are mixed up. Here is my code that includes both the game with the LCD display. If there are any master coders here do you think the code is the problem or its just not possible to do :(?

int Led1Pin = 6; //The pin of the first LED.
int Led2Pin = 7; //The pin of the second LED.
int Led3Pin = 8; //etc.
int Led4Pin = 9;
int Led5Pin = 10;

int ButtonPin = 13; //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();

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16, 2);
  
  pinMode(Led1Pin, OUTPUT);
  pinMode(Led2Pin, OUTPUT);
  pinMode(Led3Pin, OUTPUT);
  pinMode(Led4Pin, OUTPUT);
  pinMode(Led5Pin, OUTPUT);
  pinMode(ButtonPin, INPUT);

  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 >= 10) LightPosition = 5;
    
    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 == 7)
    {
      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
      lcd.println("GAME OVER");
      lcd.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)
{
  
 //Turn off all LEDs
for (int x = Led1Pin; x <= Led5Pin;x++)
{
  digitalWrite(x, LOW);
}

//Turn on the LED
digitalWrite(LightPosition + 1, HIGH);
}

void newGame()
{
  LightPosition = 0;
  pause = 1000;
  Serial.println("New Game: Score 1000");
}

Just to clarify, can you get the Hello World example to work with your hardware setup?

I tried uploading Hello World code on my current setup, and nothing came on. Also I don't know if it is relevant, but I can only turn my potentiometer about 20% before the display goes completely dark.

In which case your hardware is either wired up wrong or you have a faulty display. Get the Hello Workd working before trying to get the display into your game.

What about the schematic you are constantly being asked for?

Took me a while, but its the best I could do...

Also, I swapped the LCD displays in between videos and the LCD in this video is the 2nd display I used. Notice how when I turn the brightness down half the display dims first, the 1st lcd display didn't do this...?

Sorry but that is useless. First off it is not even a schematic it is a physical layout diagram. Second you can not see where the wires go, it is just a mess.
Thirdly it is not posted correctly, you need it as an image not an attachment.

You did change the pins in the Hello World examples to reflect how you think you have wired up your LCD?

yes, code for hello world uses pins 12,11,5,4,3,2 and that is how it is wired in my board. I used this diagram as a reference for my lcd display.