My code doesn't work

My code is supposed to have the lcd keypad shield, when left pressed, to turn the led off. But it doesn't work. the lcd keypad shield just flickers when i press left. here is the code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);



void setup() {

  /* Initialise l'écran LCD */
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("CmdOS");
  delay(3000);
}


/** Fonction loop() */
void loop() {


  int LED = 52;
  pinMode(LED, OUTPUT);
  int x;
  x = analogRead(0);
  if (x < 800) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Right = LED ON,");
    lcd.setCursor(0, 1);
    lcd.print("Left = LED Off.");


    if (x < 60) {
      lcd.clear();
      lcd.print("LED On");
      if (x < 800) {
        digitalWrite(LED, HIGH);
      } else if (x < 600) {
        lcd.clear();
        lcd.print("LED Off");
        digitalWrite(LED, LOW);
      }
    };
  }
};









/**
 * Fonction de configuration de l'écran LCD pour la barre de progression.
 * Utilise les caractéres personnalisés de 0 à 5 (6 et 7 restent disponibles).
 */

// You can have up to 10 menu items in the menuItems[] array below without having to change the base programming at all. Name them however you'd like. Beyond 10 items, you will have to add additional "cases" in the switch/case
// section of the operateMainMenu() function below. You will also have to add additional void functions (i.e. menuItem11, menuItem12, etc.) to the program.

Gee what a mess!!!!
Please press ctrl-t in the IDE and copy paste the code again...

@build_1971 Ctrl-t doesn't do nothing. i am running v2.3.2 of the IDE

Try Tools/Auto Format instead

@UKHeliBob it still flickers and when i press auto format it does nothing

Pressing ctl-t or Tools/AutoFormat does not change the behaviour of the sketch. It formats the code text ( does correct indentation ) to be better readable and understandable.

After doing so, it looks like this:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);



void setup() {

  /* Initialise l'écran LCD */
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("CmdOS");
  delay(3000);
}


/** Fonction loop() */
void loop() {


  int LED = 52;
  pinMode(LED, OUTPUT);
  int x;
  x = analogRead(0);
  if (x < 800) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Right = LED ON,");
    lcd.setCursor(0, 1);
    lcd.print("Left = LED Off.");


    if (x < 60) {
      lcd.clear();
      lcd.print("LED On");
      if (x < 800) {
        digitalWrite(LED, HIGH);
      } else if (x < 600) {
        lcd.clear();
        lcd.print("LED Off");
        digitalWrite(LED, LOW);
      }
    };
  };
};







/**
 * Fonction de configuration de l'écran LCD pour la barre de progression.
 * Utilise les caractéres personnalisés de 0 à 5 (6 et 7 restent disponibles).
 */

// You can have up to 10 menu items in the menuItems[] array below without having to change the base programming at all. Name them however you'd like. Beyond 10 items, you will have to add additional "cases" in the switch/case
// section of the operateMainMenu() function below. You will also have to add additional void functions (i.e. menuItem11, menuItem12, etc.) to the program.

The nested if(...)s with overlapping conditions looks confusing/confused. Especially with the inconsistent indenting.

For instance if x<60, then both x<800 and x<600 is true.

I imagine it flickers because some bit of the logic is conflicting and maybe you expect the screen change only when the button changes, not every time through the loop when the reading is unchanged from before.

The else if (x < 600) clause above will never be executed....because it can only reach here if x<60, and also x > 800. This whole clause will simplify to:

    if (x < 60) {
      lcd.clear();
      lcd.print("LED On");
      digitalWrite(LED, HIGH);
    };

Ya'll i fixed the code so can you see it now and tell me whats going on?!

See #8...

You have clear() in the loop. It may get executed multiple times per second...
That will cause glitches...
Better not clear the screen but simply overwrite.
Maybe add a timer (or delay(500)) to do the writing twice a second or so... lcd screens are not the fastest screens....

idk whats going on but it STILL FLICKERS

Post your new code...

Clearing causes flickers.

Clearing every time through the loop causes frequent flickers.

What is going on is you copy/pasted a bad sketch that you do not understand. You must learn to program before you copy/paste more bad code. You should learn to the point where you do not need help. THAT is what is going on.

Change these two lines:

      // lcd.clear();
      lcd.print("LED On ");

here:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);



void setup() {
  /* Initialise l'écran LCD */
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(4, 0);
  
}


/** Fonction loop() */
void loop() {


  int LED = 52;
  pinMode(LED, OUTPUT);
  int x;
  x = analogRead(0);
  lcd.print("CmdOS");
  delay(3000);
  if (x < 800) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Right = LED ON,");
    lcd.setCursor(0, 1);
    lcd.print("Left = LED Off.");


    if (x < 60) {
      
      lcd.print("LED On");
      if (x < 800) {
        digitalWrite(LED, HIGH);
      } else if (x < 600) {
        lcd.print("LED Off");
        digitalWrite(LED, LOW);
      }
    };
  }
};









/**
 * Fonction de configuration de l'écran LCD pour la barre de progression.
 * Utilise les caractéres personnalisés de 0 à 5 (6 et 7 restent disponibles).
 */

// You can have up to 10 menu items in the menuItems[] array below without having to change the base programming at all. Name them however you'd like. Beyond 10 items, you will have to add additional "cases" in the switch/case
// section of the operateMainMenu() function below. You will also have to add additional void functions (i.e. menuItem11, menuItem12, etc.) to the program.

@baconyy33
Your new code has the same issues that the first one.
Do you understand nothing that they wrote you in posts 7 and 8?

oh wait i see the problem let me paste the code again

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);



void setup() {
  /* Initialise l'écran LCD */
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("CmdOS");
  delay(3000);
  
}


/** Fonction loop() */
void loop() {


  int LED = 52;
  pinMode(LED, OUTPUT);
  int x;
  x = analogRead(0);
  
  if (x < 800) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Right = LED ON,");
    lcd.setCursor(0, 1);
    lcd.print("Left = LED Off.");


    if (x < 60) {
      
      
    if (x < 60) {
      lcd.clear();
      lcd.print("LED On");
      digitalWrite(LED, HIGH);
    };
      } else if (x < 600) {
        lcd.print("LED Off");
        digitalWrite(LED, LOW);
      }
    };
  }









/**
 * Fonction de configuration de l'écran LCD pour la barre de progression.
 * Utilise les caractéres personnalisés de 0 à 5 (6 et 7 restent disponibles).
 */

// You can have up to 10 menu items in the menuItems[] array below without having to change the base programming at all. Name them however you'd like. Beyond 10 items, you will have to add additional "cases" in the switch/case
// section of the operateMainMenu() function below. You will also have to add additional void functions (i.e. menuItem11, menuItem12, etc.) to the program.


the last code simply won't compile because of the parentheses you added

on the else if part?