getting error message " lcd was not declared in this scope" [SOLVED]

hi everyone !
i'm still experimenting with the liquidCrystal library , i tried this code :

#include<LiquidCrystal.h>
void setup(){
  LiquidCrystal lcd(12,11,5,4,3,2);
  lcd.begin(16,2);
  byte custom[8]={B00000,B11111,B00000,B11111,B00000,B11111,B00000,B11111};
  lcd.createChar(1,custom);
  
}
void loop(){
  
  lcd.write(1);
  delay(5000);
}

but i get the error message " lcd was not declared in this scope " .
i tried re-defining the lcd variable inside the loop bloc and it worked but why do i get this error ? i thought i only had to define variables in the setup bloc only , not twice ( in the setup AND in the loop bloc) :~ i would apreciate your help
oh and i also noticed another issue !!
after i modified the code to this :

#include<LiquidCrystal.h>
void setup(){
  LiquidCrystal lcd(12,11,5,4,3,2);
  lcd.begin(16,2);
  byte custom_one[8]={B00000,B11111,B00000,B11111,B00000,B11111,B00000,B11111};
  byte custom_two[8]={B
  lcd.createChar(1,custom);
  
}
void loop(){
  LiquidCrystal lcd(12,11,5,4,3,2);
  lcd.begin(16,2);
  lcd.write(1);
  delay(5000);
  lcd.clear();
}

the programm worked fine ( displaying four separate horizontal lines ) , but after the second or third loop , i notice that an unexpected line appears between the two top horizontal lines so i get three horizontal lines with no space between them and two separate lines at the bottom :confused: :confused: please help

You declared lcd inside setup() so it is not visible inside loop(). Typically you would put the declaration of lcd outside the functions, in global scope, at the top of your sketch.

Hi

try this:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

void setup(){
  
  lcd.begin(16,2);
  byte custom[8]={B00000,B11111,B00000,B11111,B00000,B11111,B00000,B11111};
  lcd.createChar(1,custom);
  
}
void loop(){
  
  lcd.write(1);
  delay(5000);
}

liquidcrystal definition was on wrong place.

alright john , problem fixed , thanks a lot !! :wink:

arssant:
Hi

try this:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup(){
 
  lcd.begin(16,2);
  byte custom[8]={B00000,B11111,B00000,B11111,B00000,B11111,B00000,B11111};
  lcd.createChar(1,custom);
 
}
void loop(){
 
  lcd.write(1);
  delay(5000);
}




liquidcrystal definition was on wrong place.

yes i got it fixed now thanks !