How to control LCD Screen with Push buttons?

Hello,
I’m new to coding and am currently working on a light-up ukulele to show people where to place their fingers when learning to play basic chords and scales. I’m also using a 16X2 LCD screen with an I2C module controlled by push buttons to change between screens (when a chord/scale is selected the LED’s in the ukulele fretboard will light up as well). I am having a bit of trouble with getting the LCD screen reacting to when the push buttons are pressed. I’m running all this through an Arduino Microcontroller.

How the buttons are meant to work:
Home button to set the screens back to the home screen (chords/scales)
The cycle button to cycle between screens (between chords or scales)(or note quality or notes)
The select button to select when screen you want to continue with ( e.g. choose “chords”)
(please find a map of the screens attached)

Any help would be much appreciated.
Thank you.

Here is the code I have so far:

//This program will allow users to control an lcd screen and leds lights using push buttons.

//different libraries to include
#include <Wire.h> // Allows the use and communication of an I2C device.(device connected to LCD screen)
#include <LiquidCrystal_I2C.h>  // Allows use and control of LCD Screen
#include <Adafruit_NeoPixel.h>  //Allows use of WS2812B RGB LEDs (LEDs that can be individually addressed)
#include <FastLED.h>  // Allows the programing of individually addressable LEDs


// set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd {0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE};


//Constants that cannot be changed

//Assigning Button Pins
const int  Home_buttonPin  = 2;     // Go to home page (chords and scales).   - - - Connect to Pin 2 on Arduino
const int  Cycle_buttonPin = 3;     // Select a chord or scale.   - - - Connect to Pin 3 on Arduino
const int  Select_buttonPin = 4;    // Cycle through different categories until one is selected.  - - - Connect to Pin 4 on Arduino

int page_counter = 1;       //To move beetwen pages
int subpage1_counter = 0;    //To move submenu 1 Chords - Major/Minor
int subpage2_counter = 0;   //To move submenu 2 Scales - Major/Minor

int subpage1_1_counter = 0;   //To move submenu 1.1 Chords - Major/A,B,C,D,E,F,G
int subpage2_1_counter = 0;   //To move submenu 2.1 Chords - Minor/A,B,C,D,E,F,G

int subpage1_2_counter = 0;   //To move submenu 1.2 Scales - Major/A,B,C,D,E,F,G
int subpage2_2_counter = 0;   //To move submenu 2.2 Scales - Minor/A,B,C,D,E,F,G

//Assigning LED pins
const int LED_Pin = 9;             // lED pin connected to arduino.   - - - Connect to Pin 9 on Arduino

//Stating the Number of LEDs to be used
const int NUM_LEDS = 52;           // Number of lEDs used

//Stating the mode of colour
CRGB leds[NUM_LEDS];              // Colour mode


//  - - - Connect to Pin A4 on Arduino


//Stating the variables that will change
//Button States
boolean Home_buttonState = 0;             // Current state of the home button
boolean Home_buttonStateLast = 0;         // Previous state of the home button
boolean Home_buttonStateHeld = 0;
boolean Cycle_buttonState = 0;            // Current state of the cycle button
boolean Cycle_buttonStateLast = 0;        // Previous state of the cycle button
boolean Select_buttonState = 0;           // Current state of the select button
boolean Select_buttonStateLast = 0;       // Previous state of the select button


//LED Brightness
int brightness = 120;

int charindex = 0;
int charsSize = 0;





void setup() {
  Serial.begin(9600);    // Sets the data rate in bits per second


  FastLED.addLeds<WS2812B, LED_Pin, GRB>(leds, NUM_LEDS); // Identify type of LED strip?

  // initialise LCD screen
  lcd.begin(16, 2);             // Tells LCD to begin with 16 characters and 2 lines displayed
  lcd.clear();                  // Clears all text from LCD Screen
  lcd.setCursor(0, 0);          // Sets cursor to top left corner.
  lcd.print("Guitar Aid");      // Print opening Text  - - - - - Remember to change name here.
  delay(3000);                  // Leaves opening text on screen for 5 seconds
  lcd.clear();



  //5V LED supply
  // pinMode(ledSupplyEnablePin, OUTPUT);
  // digitalWrite(ledSupplyEnablePin, 0);




  // initialise the pushbutton pin as an input:
  pinMode  (Home_buttonPin, INPUT_PULLUP);     //Set home button as an imput.
  pinMode  (Cycle_buttonPin, INPUT_PULLUP);    //Set cycle button as an imput.
  pinMode  (Select_buttonPin, INPUT_PULLUP);   //Set select button as an imput.

}



void loop() {

  // Initialise the pushbuttons
  Home_buttonStateLast = Home_buttonState;
  Cycle_buttonStateLast = Cycle_buttonState;
  Select_buttonStateLast = Select_buttonState;

  Home_buttonState = digitalRead (Home_buttonPin);
  Cycle_buttonState = digitalRead (Cycle_buttonPin);
  Select_buttonState = digitalRead (Select_buttonPin);

  //Change pages
  if  (Home_buttonStateLast == LOW && Home_buttonState == HIGH) { //Home button pressed
    Home_buttonStateLast == Home_buttonStateHeld;
    page_counter = 1 ;

  }





  if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
    page_counter = 2;
    if (page_counter < 2) {           //Page counter not higher than 2 (total of pages for home)
      page_counter = page_counter + 1;  //Page up

    }
    else {
      page_counter = 1;                 //If higher than 2 (last page) change back to page 1
    }
  }





  switch (page_counter) {

    case 1: {    //Design of home page 1
        lcd.setCursor(0, 0);
        lcd.print("Chords");
      }//case 1 end
      break;


    case 2: {    //Design of home page 2
        lcd.setCursor(0, 0);
        lcd.print("Scales");
      }//case 2 end
      break;
  }

  // Sub1 counter control
  if (Select_buttonStateLast == LOW && Select_buttonState == HIGH) { //select button pressed

    if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
      subpage1_counter = 2;
      if (subpage1_counter < 2) {           // SubPage counter not higher than 2 (total of pages for home)
        subpage1_counter = subpage1_counter + 1;   //Page up

        subpage1_counter ++;                         //subcounter to move beetwen submenu
      }
      else {                                      //If subpage higher than 2 (total of items) return to first item
        subpage1_counter = 1;
      }
    }
                          
  }


  switch (subpage1_counter) {

    case 1: {    //Design of note quality page 1
        lcd.setCursor(0, 0);
        lcd.print("Chords: Major");
      }//case 1 end
      break;


    case 2: {    //Design of note quality page 2
        lcd.setCursor(0, 0);
        lcd.print("Chords: Minor");
      }//case 2 end
      break;

  }


  // Sub2 counter control
  if (Select_buttonStateLast == LOW && Select_buttonState == HIGH) { //select button pressed

    if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
      subpage2_counter = 2;
      if (subpage2_counter < 2) {           // SubPage counter not higher than 2 (total of pages for home)
        subpage2_counter = subpage1_counter + 1;   //Page up

        subpage2_counter ++;                         //subcounter to move beetwen submenu
      }
      else {                                      //If subpage higher than 2 (total of items) return to first item
        subpage2_counter = 1;
      }
    }
                          
  }


  switch (subpage2_counter) {

    case 1: {    //Design of note quality page 1
        lcd.setCursor(0, 0);
        lcd.print("Scales: Major");
      }//case 1 end
      break;


    case 2: {    //Design of note quality page 2
        lcd.setCursor(0, 0);
        lcd.print("Scales: Minor");
      }//case 2 end
      break;

  }




  // Sub1_1 counter control
  if (Select_buttonStateLast == LOW && Select_buttonState == HIGH) { //select button pressed

    if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
      subpage1_1_counter = 7;
      if (subpage1_1_counter < 7) {           // SubPage counter not higher than 7 (total of pages for home)
        subpage1_1_counter = subpage1_counter + 1;   //Page up

        subpage1_1_counter ++;                         //subcounter to move beetwen submenu
      }
      else {                                      //If subpage higher than 7 (total of items) return to first item
        subpage1_1_counter = 1;
      }
    }
    //  Select_buttonStateLast = Select_buttonState;                      
  }


  switch (subpage1_1_counter) {

    case 1: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: A Major");
      }//case 1 end
      break;

    case 2: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: B Major");
      }//case 1 end
      break;

    case 3: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: C Major");
      }//case 1 end
      break;

    case 4: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: D Major");
      }//case 1 end
      break;

    case 5: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: E Major");
      }//case 1 end
      break;

    case 6: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: F Major");
      }//case 1 end
      break;

    case 7: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: G Major");
      }//case 1 end
      break;


  }


  // Sub2_1 counter control
  if (Select_buttonStateLast == LOW && Select_buttonState == HIGH) { //select button pressed

    if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
      subpage2_1_counter = 7;
      if (subpage2_1_counter < 7) {           // SubPage counter not higher than 7 (total of pages for home)
        subpage2_1_counter = subpage1_counter + 1;   //Page up

        subpage2_1_counter ++;                         //subcounter to move beetwen submenu
      }
      else {                                      //If subpage higher than 7 (total of items) return to first item
        subpage2_1_counter = 1;
      }
    }
                          
  }


  switch (subpage2_1_counter) {

    case 1: {  
        lcd.setCursor(0, 0);
        lcd.print("Chords: A Major");
      }//case 1 end
      break;

    case 2: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: B Major");
      }//case 1 end
      break;

    case 3: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: C Major");
      }//case 1 end
      break;

    case 4: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: D Major");
      }//case 1 end
      break;

    case 5: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: E Major");
      }//case 1 end
      break;

    case 6: {  
        lcd.setCursor(0, 0);
        lcd.print("Chords: F Major");
      }//case 1 end
      break;

    case 7: { 
        lcd.setCursor(0, 0);
        lcd.print("Chords: G Major");
      }//case 1 end
      break;


  }





  // Sub1_2 counter control
  if (Select_buttonStateLast == LOW && Select_buttonState == HIGH) { //select button pressed

    if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
      subpage1_2_counter = 7;
      if (subpage1_2_counter < 7) {           // SubPage counter not higher than 7 (total of pages for home)
        subpage1_2_counter = subpage1_counter + 1;   //Page up

        subpage1_2_counter ++;                         //subcounter to move beetwen submenu
      }
      else {                                      //If subpage higher than 7 (total of items) return to first item
        subpage1_2_counter = 1;
      }
    }
                          
  }


  switch (subpage1_2_counter) {

    case 1: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: A Minor");
      }//case 1 end
      break;

    case 2: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: B Minor");
      }//case 1 end
      break;

    case 3: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: C Minor");
      }//case 1 end
      break;

    case 4: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: D Minor");
      }//case 1 end
      break;

    case 5: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: E Minor");
      }//case 1 end
      break;

    case 6: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: F Minor");
      }//case 1 end
      break;

    case 7: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: G Minor");
      }//case 1 end
      break;


  }


  // Sub2_2 counter control
  if (Select_buttonStateLast == LOW && Select_buttonState == HIGH) { //select button pressed

    if (Cycle_buttonStateLast == LOW &&   Cycle_buttonState == HIGH) { //cycle button pressed
      subpage2_2_counter = 7;
      if (subpage2_2_counter < 7) {           // SubPage counter not higher than 7 (total of pages for home)
        subpage2_2_counter = subpage1_counter + 1;   //Page up

        subpage2_2_counter ++;                         //subcounter to move beetwen submenu
      }
      else {                                      //If subpage higher than 7 (total of items) return to first item
        subpage2_2_counter = 1;
      }
    }
                          
  }


  switch (subpage2_2_counter) {

    case 1: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: A Minor");
      }//case 1 end
      break;

    case 2: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: B Minor");
      }//case 1 end
      break;

    case 3: {   
        lcd.setCursor(0, 0);
        lcd.print("Chords: C Minor");
      }//case 1 end
      break;

    case 4: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: D Minor");
      }//case 1 end
      break;

    case 5: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: E Minor");
      }//case 1 end
      break;

    case 6: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: F Minor");
      }//case 1 end
      break;

    case 7: {    
        lcd.setCursor(0, 0);
        lcd.print("Chords: G Minor");
      }//case 1 end
      break;


  }

}

What sort of trouble are you having with the buttons ?

NOTE: the file that you attached/uploaded is on your PC and cannot be seen here. Open it in Paint, select all of it, Copy to the clipboard and paste it into a post here

Hi,
I’ve just edited the original post, hopefully you can see the image now.

When I run this code, the screen opens with “Guitar Aid” and then changes to “Chords: Major” (but the pixels on the screen seem to be trying to display both “major” and “minor” at the same time). and nothing happens when I push any of the buttons.

I do know that both the buttons and screen work as I am able to run other codes on them just fine.

Hello
My standard recipe:
As a basis, study the IPO model and then take a bag of data structures, timers and a small finite state machine and stir everything together to the desired functionality. And don’t forget the seasoning.
INPUT: Home_buttonPin , Cycle_buttonPin, Select_buttonPin, inclusive debouncing.
PROCESSING: selection of the page related to pushed button
OUTPUT: displaying of selected page