Help for LCD connection and code for simon says

Hi, Im new to arduino and programming in general and I wanted to include a LCD screen that shows the score and highscore of my Simon says project, but i don't really know how to start and how to do it, in terms of programing and connections.
here is my circuit. Thanks in advance

And here is my code

#define NOTE_A4  440

#define NOTE_AS4 466

#define NOTE_B4  494

#define NOTE_C5  523

#define NOTE_CS5 523

#define startButton 2

#define button1  3

#define button2  4

#define button3  5

#define button4  6

#define LED1 7

#define LED2  8

#define LED3 9

#define LED4  10

#define buzzer  11

#include <LiquidCrystal.h>

LiquidCrystal lcd(22, 23, 24, 25, 26 , 27);

const int MAX_LEVEL = 100;

int sequence[MAX_LEVEL];

int your_sequence[MAX_LEVEL];

int level = 1;

int velocity = 1000;

void setup() {

  pinMode(startButton, INPUT);

  pinMode(button1, INPUT);

  pinMode(button2, INPUT);

  pinMode(button3, INPUT);

  pinMode(button4, INPUT);

  pinMode(LED1, OUTPUT);

  pinMode(LED2, OUTPUT);

  pinMode(LED3, OUTPUT);

  pinMode(LED4, OUTPUT);

  pinMode(buzzer, OUTPUT);

  digitalWrite(LED1, LOW);

  digitalWrite(LED2, LOW);

  digitalWrite(LED3, LOW);

  digitalWrite(LED4, LOW);

}

void loop()

{

  if (level == 1)

    generate_sequence();//generate a sequence;

  if (digitalRead(startButton) == LOW || level != 1) //If start button is pressed or you're winning

  {

    show_sequence();    //show the sequence

    get_sequence();     //wait for your sequence

  }

  noTone(buzzer);

}

void show_sequence()

{

  digitalWrite(LED1, LOW);

  digitalWrite(LED2, LOW);

  digitalWrite(LED3, LOW);

  digitalWrite(LED4, LOW);

  for (int i = 0; i < level; i++)

  {

    switch (sequence[i]) {

      case (2):

        digitalWrite(LED1, HIGH);

        tone(buzzer, NOTE_CS5, 100);

        delay(velocity);

        digitalWrite(LED1, LOW);

        noTone(buzzer);

        delay(200);

        break;

      case (3):

        digitalWrite(LED2, HIGH);

        tone(buzzer, NOTE_B4, 100);

        delay(velocity);

        digitalWrite(LED2, LOW);

        noTone(buzzer);

        delay(200);

        break;

      case (4):

        digitalWrite(LED3, HIGH);

        tone(buzzer, NOTE_AS4, 100);

        delay(velocity);

        digitalWrite(LED3, LOW);

        noTone(buzzer);

        delay(200);

        break;

      case (5):

        digitalWrite(LED4, HIGH);

        tone(buzzer, NOTE_A4, 100);

        delay(velocity);

        digitalWrite(LED4, LOW);

        noTone(buzzer);

        delay(200);

        break;

    }

  }

  noTone(buzzer);

}

void get_sequence()

{

  int flag = 0; //this flag indicates if the sequence is correct

  for (int i = 0; i < level; i++)

  {

    flag = 0;

    while (flag == 0)

    {

      if (digitalRead(button4) == LOW)

      {

        digitalWrite(LED4, HIGH);

        your_sequence[i] = 5;

        tone(buzzer, NOTE_A4, 100);

        flag = 1;

        delay(200);

        if (your_sequence[i] != sequence[i])

        {

          wrong_sequence();

          return;

        }

        digitalWrite(LED4, LOW);

      }

      if (digitalRead(button3) == LOW)

      {

        digitalWrite(LED3, HIGH);

        your_sequence[i] = 4;

        tone(buzzer, NOTE_AS4, 100);

        flag = 1;

        delay(200);

        if (your_sequence[i] != sequence[i])

        {

          wrong_sequence();

          return;

        }

        digitalWrite(LED3, LOW);

      }

      if (digitalRead(button2) == LOW)

      {

        digitalWrite(LED2, HIGH);

        your_sequence[i] = 3;

        tone(buzzer, NOTE_B4, 100);

        flag = 1;

        delay(200);

        if (your_sequence[i] != sequence[i])

        {

          wrong_sequence();

          return;

        }

        digitalWrite(LED2, LOW);

      }

      if (digitalRead(button1) == LOW)

      {

        digitalWrite(LED1, HIGH);

        your_sequence[i] = 2;

        tone(buzzer, NOTE_CS5, 100);

        flag = 1;

        delay(200);

        if (your_sequence[i] != sequence[i])

        {

          wrong_sequence();

          return;

        }

        digitalWrite(LED1, LOW);

      }

    }

  }

  noTone(buzzer);

  right_sequence();

}

void generate_sequence()

{

  randomSeed(millis()); //in this way is really random!!!

  for (int i = 0; i < MAX_LEVEL; i++)

  {

    sequence[i] = random(2, 6);

  }

}

void wrong_sequence()

{

  for (int i = 0; i < 3; i++)

  {

    digitalWrite(LED1, HIGH);

    digitalWrite(LED2, HIGH);

    digitalWrite(LED3, HIGH);

    digitalWrite(LED4, HIGH);

    tone(buzzer, 30);

    delay(250);

    digitalWrite(LED1, LOW);

    digitalWrite(LED2, LOW);

    digitalWrite(LED3, LOW);

    digitalWrite(LED4, LOW);

    tone(buzzer, 10);

    delay(250);

  }

  noTone(buzzer);

  level = 1;

  velocity = 1000;

}

void right_sequence()

{

  delay(500);

  digitalWrite(LED1, HIGH);

  digitalWrite(LED2, HIGH);

  digitalWrite(LED3, HIGH);

  digitalWrite(LED4, HIGH);

  tone(buzzer, NOTE_A4);

  delay(250);

  digitalWrite(LED1, LOW);

  digitalWrite(LED2, LOW);

  digitalWrite(LED3, LOW);

  digitalWrite(LED4, LOW);

  tone(buzzer, NOTE_AS4);

  delay(250);

  digitalWrite(LED1, HIGH);

  digitalWrite(LED2, HIGH);

  digitalWrite(LED3, HIGH);

  digitalWrite(LED4, HIGH);

  tone(buzzer, NOTE_B4);

  delay(250);

  digitalWrite(LED1, LOW);

  digitalWrite(LED2, LOW);

  digitalWrite(LED3, LOW);

  digitalWrite(LED4, LOW);

  tone(buzzer, NOTE_CS5);

  delay(1200);

  noTone(buzzer);

  delay(500);

  if (level < MAX_LEVEL);

  level++;

  velocity -= 50; //increase difficulty

}

There is example code like "blink en LED", "Blink without delay". Have You tried any of them?7

What is the setup supposed to do and what does it actually do?-

Please post real schematics, not a coloured bird nest picture.

I would suggest an I2C enabled version of the 1602 or 2004 LCD. That only needs 2 pins instead of 6.

Then use the hd44780 library to control the LCD. The library comes with extensive documentation and example code. Install the library using the IDE library manager.

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