LCD Display not working as planned

I'm writing on a code for a game, I'm just at the beginning with the writing but I have a problem...For the beginning of the game I thought of making an Intro with lights, sounds and on the LCD Display it says: Strat Fighters! (the name of the game). After that it should show something on the display like Player 1. But after the sounds etc. the display just cleares. I tried putting the command (lcd.print("Player 1")) after the sounds in the void intro, after the void intro in the loop and it still doesn't function. It just skips the command. I tried and put a command for turning on an LED an that function, but the lcd.print just gets skipped. How can that be? Thanks for your help!


#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int led_gelb = 7;
int led_grun = 8;
int led_blau = 9;
int led_rot = 10;
int buzzer_one = 1;
int buzzer_two = 0;
int buzzer_three = 13;
int speaker = 6;

int one_status;
int two_status;
int three_status;

int health_gelb;
int health_grun;
int health_blau;
int health_rot;

int spieler_dran;

int win_a;
int win_b;

void setup() {
  // put your setup code here, to run once:

  lcd.begin(16, 2);

  pinMode(led_gelb, OUTPUT);
  pinMode(led_grun, OUTPUT);
  pinMode(led_blau, OUTPUT);
  pinMode(led_rot, OUTPUT);
  pinMode(buzzer_one, INPUT_PULLUP);
  pinMode(buzzer_two, INPUT_PULLUP);
  pinMode(buzzer_three, INPUT_PULLUP);
  pinMode(speaker, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:


  lcd.clear();
  win_a = false;
  win_b = false;


  one_status = digitalRead(buzzer_one);
  two_status = digitalRead(buzzer_two);
  three_status = digitalRead(buzzer_three);

  //Wenn beide Buttons gedrückt sind startet das Spiel

  if (one_status == LOW && three_status == LOW) {

    intro();

    lcd.print("Player 1");

    digitalWrite(led_gelb, HIGH);
  }
}

void intro() {

  //INTRO MIT LICHTERN UND SOUND
  lcd.setCursor(0, 0);
  lcd.print("STRAT FIGHTERS!");
  digitalWrite(led_gelb, HIGH);
  tone(speaker, 63);
  delay(150);
  digitalWrite(led_grun, HIGH);
  tone(speaker, 126);
  delay(150);
  digitalWrite(led_blau, HIGH);
  tone(speaker, 189);
  delay(150);
  digitalWrite(led_rot, HIGH);
  tone(speaker, 255);
  delay(150);
  digitalWrite(led_rot, LOW);
  tone(speaker, 189);
  delay(150);
  digitalWrite(led_blau, LOW);
  tone(speaker, 126);
  delay(150);
  digitalWrite(led_grun, LOW);
  tone(speaker, 63);
  delay(150);
  digitalWrite(led_gelb, LOW);
  noTone(speaker);
  delay(750);
  digitalWrite(led_gelb, HIGH);
  digitalWrite(led_grun, HIGH);
  digitalWrite(led_blau, HIGH);
  digitalWrite(led_rot, HIGH);
  tone(speaker, 255);
  delay(1500);
  noTone(speaker);
  digitalWrite(led_gelb, LOW);
  digitalWrite(led_grun, LOW);
  digitalWrite(led_blau, LOW);
  digitalWrite(led_rot, LOW);
  lcd.clear();
}

probably working fine, you just need to remember, you're in a loop..
probably going to spend most of it's time in the intro, over and over..

you need to keep track of your game state..

board did a pong game last week..
pong-paddle-on-lcd-is-updating-too-late
got some sims in there, might be a good read for you..

have fun, good luck.. ~q

Don't use pin 0 or 1

On Edit: My bad. I didn't realize he's using lcd.print. 0 and 1 shouldn't matter.

Hi, @dnoopp
Welcome to the forum.

Thanks for using code tags.

What model Arduino are you using?
Note that you are clearing the LCD at the start of each loop, so something put on the LCD might not be there long enough for you to see.

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

I'm using a ELEGOO UNO R3

Thanks mate! I really didn't think about the lcd.clear() at the beginning. Huge THANKS!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.