How to disable a button after when you pressed a button on the lcd

hello everyone i got a problem, when ever i try to set the " ''' digitalWrite(buttonone, 1);
digitalWrite(buttontwo, 1); " ''' on 0 the screen gets sometimes glitched when you press a button which has the code in it my project consists of six buttons 4 are pushbuttons for apps and 2 are for menu scroll. also please suggest me a button menu scroll code. here is my code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
 
 #define buttonone 2  
 #define buttontwo 3  
 #define buttonthree 4
 #define buttonfour 5
 #define buttonfive 6
 #define buttonsix 7
 int state = 1;  
 void setup()   
 {  
  Serial.begin(9600);  
  pinMode(buttonone, INPUT_PULLUP);  
  pinMode(buttontwo, INPUT_PULLUP);  
  pinMode(buttonthree, INPUT_PULLUP);
  pinMode(buttonfour, INPUT_PULLUP);
  pinMode(buttonfive, INPUT_PULLUP);
  pinMode(buttonsix, INPUT_PULLUP);

  lcd.begin();
  lcd.backlight();
  lcd.setCursor ( 0, 0 );
  lcd.print("grapics test");
  lcd.setCursor(0,1);
  lcd.print("hack!!>L.C.D.oi");
  
  

  digitalWrite(buttonone, 1);   
  digitalWrite(buttontwo, 1);   
  digitalWrite(buttonthree, 1); 
  digitalWrite(buttonfour,1);
  digitalWrite(buttonfive,1);
  digitalWrite(buttonsix,1);
   
  delay(200);  
 }  
 void loop()   
 { 
  state = digitalRead(buttonsix);  
  if (state != 1) {                   // menu 2
    lcd.clear();
   
    
    lcd.setCursor(0,0);
    lcd.print("boot menu");
    lcd.setCursor(0,1);
    lcd.print("music player");
  }
  
  state = digitalRead(buttonone);      // app 1 
  if (state != 1) { 
    lcd.clear(); 
    lcd.print("under counstrucstion");  
  }
  
  lcd.setCursor(0, 1);   
  state = digitalRead(buttontwo);      // app 2
  if (state != 1) {  
    lcd.clear();
    lcd.print("under counstrucstion");  
  }

  lcd.setCursor(0, 2);
  state = digitalRead(buttonthree);    // app 3
  if (state != 1) {
    lcd.clear();  
   lcd.print("under counstruction");
 
  } 
state = digitalRead(buttonfour);  // app 4
  if (state != 1) {
    lcd.clear();  
   lcd.print("under counstruction");
 
  } 
  state = digitalRead(buttonfive);  //menu 1
  if (state != 1) {
    lcd.clear(); 
   

     lcd.setCursor ( 0, 0 );
  lcd.print("grapics test");
  lcd.setCursor(0,1);
  lcd.print("hack!!>L.C.D.oi");
   
 
  } 
 }
```please help me as this is my first Arduino project

the problem is that the menu buttons have a code in which when you press menu 1 the app button 3 and 4 gets disabled and when i press that button it shows a glitchy text . actually the apps are written ' under construction ' so it shows that on my lcd

digitalWrite(buttonone, 1);
. . .
digitalWrite(buttonsix,1);

Tell us what you think the lines of code above do ?


Review this:

FYI

digital read button one to four are pushbutton when you press any of them they react
and digital read six and five are for menu
the thing is i want to put a command in which when you press digital read six it should disable digital read button 1 and 3 and when its digital read button five it should disable button 3 and 4

also i am a beginner so i dont know much

What happens with this sketch ?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

//********************************************^************************************************
#define PUSHED      LOW
#define RELEASED    HIGH

#define buttonone   2
#define buttontwo   3
#define buttonthree 4
#define buttonfour  5
#define buttonfive  6
#define buttonsix   7

//********************************************^************************************************

byte state;


void setup()
{
  Serial.begin(9600);
  
  pinMode(buttonone, INPUT_PULLUP);
  pinMode(buttontwo, INPUT_PULLUP);
  pinMode(buttonthree, INPUT_PULLUP);
  pinMode(buttonfour, INPUT_PULLUP);
  pinMode(buttonfive, INPUT_PULLUP);
  pinMode(buttonsix, INPUT_PULLUP);
   
  lcd.begin();
  
  lcd.backlight();
  lcd.setCursor ( 0, 0 );
  lcd.print("grapics test");
  lcd.setCursor(0, 1);
  lcd.print("Testing");

  delay(200);
  
} //END of   setup()


//********************************************^************************************************
void loop()
{
  //********************************
  state = digitalRead(buttonsix);

  if (state == PUSHED)                      // menu 2
  {
    lcd.clear();
    lcd.print("Button Six");
  }

  //********************************
  state = digitalRead(buttonone);      // app 1

  if (state == PUSHED)
  {
    lcd.clear();
    lcd.print("Button One");
  }

  lcd.setCursor(0, 1);

  //********************************
  state = digitalRead(buttontwo);      // app 2

  if (state == PUSHED)
  {
    lcd.clear();
    lcd.print("Button Two");
  }

  lcd.setCursor(0, 2);

  //********************************
  state = digitalRead(buttonthree);    // app 3

  if (state == PUSHED)
  {
    lcd.clear();
    lcd.print("Button Three");
  }

  //********************************
  state = digitalRead(buttonfour);  // app 4

  if (state == PUSHED)
  {
    lcd.clear();
    lcd.print("Button Four");
  }

  //********************************
  state = digitalRead(buttonfive);  //menu 1

  if (state == PUSHED)
  {
    lcd.clear();
    lcd.print("Button Five");
  }

} //END of     loop()


Another Example

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

//********************************************^************************************************
#define PUSHED             LOW
#define RELEASED           HIGH

//********************************************^************************************************

const byte UP            = 2;
const byte DOWN          = 3;

const byte heartbeatLED  = 13;

byte state;

byte lastUp              = RELEASED;
byte lastDown            = RELEASED;

int counter              = 1;

//
char *menuText[]         =
{
  //          Array element
  "One",    //0
  "Two",    //1
  "Three",  //2
  "Four",   //3
  "Five",   //4
  "Six"     //5
};

//timing stuff
unsigned long heartbeatMillis;
unsigned long switchMillis;

//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  Serial.begin(9600);

  pinMode(heartbeatLED, OUTPUT);

  pinMode(UP, INPUT_PULLUP);
  pinMode(DOWN, INPUT_PULLUP);

  lcd.begin();

  lcd.backlight();
  lcd.setCursor ( 0, 0 );
  lcd.print("Menu Number");
  lcd.setCursor(0, 1);
  lcd.print(menuText[counter - 1]);

} //END of   setup()


//                                       l o o p ( )
//********************************************^************************************************
void loop()
{
  //*********************************                  heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*********************************                  switch TIMER
  //is it time to check the switches ?
  if (millis() - switchMillis >= 50ul)
  {
    //restart this TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*********************************
  // Other none blocking code goes here
  //*********************************

} //END of loop()


//                              c h e c k S  w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  //********************************                  UP switch
  state = digitalRead(UP);

  if (lastUp != state)
  {
    //update to the new state
    lastUp = state;

    //was the switch PUSHED ?
    if (state == PUSHED)
    {
      //next menu
      counter++;

      //do not go past 6
      if (counter > 6)
      {
        counter = 6;
      }

      lcd.clear();
      lcd.print("Menu Number");

      lcd.setCursor(0, 1);
      lcd.print(menuText[counter - 1]);
    }
  }

  //********************************                  DOWN switch
  state = digitalRead(DOWN);

  if (lastDown != state)
  {
    //update to the new state
    lastDown = state;

    //was the switch PUSHED ?
    if (state == PUSHED)
    {
      //next menu
      counter--;

      //do not go under 1
      if (counter < 1)
      {
        counter = 1;
      }

      lcd.clear();
      lcd.print("Menu Number");

      lcd.setCursor(0, 1);
      lcd.print(menuText[counter - 1]);
    }
  }

} //END of checkSwitches()


//********************************************^************************************************

actually my project is an aurdino computer so i included six buttons as i told

sorry for the bad camera quality, anyways this is my computer thingy i have been working on

as you can see there are four buttons in the middle which are responsible for apps means when i press a button the lcd clears and shows the text

then i have 2 separate buttons the red one on the left side and the white one on the right side so those are responsible for menu <<>>> the white button is responsible for going back to the main menu and the red one is resposible for going to the second manu <<<<<>>>> now this is my main problem when ever i put the code in the menu buttons such as the white button i pu a code with says'''digitalWrite(buttonthree, 0);
digitalWrite(buttonfour,0);''' and when for the red one its opposite so when ever i press the menu buttons the lcd glitches and says the app text so i want to fix that

'<<<<<>>>>>>" it means spoiler alerts

also i am in a hurry for making this project

Do not use a digitalWrite on an input pin.

Doing so turns OFF/ON the pins internal pull-up resistor.


BTW, with digitalWrite, use HIGH/LOW not 1/0


Still confused as to what you are trying to accomplish.

You need to give a better explanation of exactly what’s needed.


Always show us your current version of the sketch you are talking about.


Also, we need to see a schematic of your proposed circuit.

ok here is my code i am having difficulty with .What i want do is i want to make a code in which when you press a button the other buttons should disable its like padlock when you put a key in it you lock it and the padlock cannot be opened without a key same way it happens in my circuit the problem is when i put the code digitalwrite( buttonone , LOW);
digitalWrite(buttontwo , LOW);
then when i press that button which has the code in it the LCD goes haywire, its starts to show the app text and my entire projected becomes haywire only when i reset it it goes back to normal untill i press that button here is my code

`#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

 #define buttonone 2

 #define buttontwo 3
 #define buttonthree 4  
 #define buttonfour 5  
 #define buttonfive 6  
 #define buttonsix 7 
 int state = 1;  
 
 void setup()   
 {  
  Serial.begin(9600);  
  pinMode(buttonone, INPUT_PULLUP);  
  pinMode(buttontwo, INPUT_PULLUP);  
  pinMode(buttonthree, INPUT_PULLUP);
  pinMode(buttonfour, INPUT_PULLUP);
  pinMode(buttonfive, INPUT_PULLUP);
  pinMode(buttonsix, INPUT_PULLUP);

  lcd.begin();
  lcd.backlight();
  lcd.setCursor ( 0, 0 );
  lcd.print("hardware test");
  lcd.setCursor(0,1);
  lcd.print("hack!!>L.C.D.oi");
  
  

  digitalWrite(buttonone, HIGH);   
  digitalWrite(buttontwo, HIGH);           
  digitalWrite(buttonthree, HIGH); 
  digitalWrite(buttonfour, HIGH);
  digitalWrite(buttonfive, HIGH);
  digitalWrite(buttonsix, HIGH);
   
  delay(200);  
 }  
 void loop()   
 { 
  state = digitalRead(buttonsix);  
  if (state != 1) {                   // menu 2
    lcd.clear();
   digitalWrite(buttonone,LOW);
   digitalWrite(buttontwo,LOW);
   
    lcd.setCursor(0,0);
    lcd.print("boot menu");
    lcd.setCursor(0,1);
    lcd.print("output cpu code");
  }
  
  state = digitalRead(buttonone);      // app 1 
  if (state != 1) { 
    lcd.clear(); 
    lcd.print("");  
  }
  
  lcd.setCursor(0, 1);   
  state = digitalRead(buttontwo);      // app 2
  if (state != 1) {  
    lcd.clear();
    lcd.print("");  
  }

  lcd.setCursor(0, 2);
  state = digitalRead(buttonthree);    // app 3
  if (state != 1) {
    lcd.clear();  
   lcd.print("");
 
  } 
state = digitalRead(buttonfour);  // app 4
  if (state != 1) {
    lcd.clear();  
   lcd.print("");
 
  } 
  state = digitalRead(buttonfive);  //menu 1
  if (state != 1) {
    lcd.clear(); 
    digitalWrite(buttonthree, LOW);
    digitalWrite(buttonfour, LOW);
   

     lcd.setCursor ( 0, 0 );
  lcd.print("grapics test");
  lcd.setCursor(0,1);
  lcd.print("hack!!>L.C.D.oi");
   
 
  } 
 }

so thats my main problem

i will soon post the schematic

Hello catfish10101

All the buttons pins are intialzied as INPUT_PULL.

What is the desired goal by doing this?

Line 33:   digitalWrite(buttonone, HIGH);   
	Line 34:   digitalWrite(buttontwo, HIGH);           
	Line 35:   digitalWrite(buttonthree, HIGH); 
	Line 36:   digitalWrite(buttonfour, HIGH);
	Line 37:   digitalWrite(buttonfive, HIGH);
	Line 38:   digitalWrite(buttonsix, HIGH);
	Line 47:    digitalWrite(buttonone,LOW);
	Line 48:    digitalWrite(buttontwo,LOW);
	Line 85:     digitalWrite(buttonthree, LOW);
	Line 86:     digitalWrite(buttonfour, LOW);

Have a nice day and enjoy programming in C++ and learning.

i am planning to make an aurdino computer with six buttons also i had savage a tally counter and extracted its lcd so i will be using my aurdino to hack it by just using ground or some pins

also paul can i set the digial write button to low so that when a button is pressed some buttons should disable?

it didnt work :frowning: all i want is when you press button six the two buttons should disable ,also i in a hurry i got 3 days left