Go Down

Topic: My LCD display say Hello and the display is filling up with lines!! (Read 132 times) previous topic - next topic

laneigeluge

Hi everyone, i have a little issues with my lcd display and i can't find how to resolve it.
I'm pretty sure than it doesn't come of the code ( but take a look).
So like the picture show us, it's start by saying "bonjour" (hello in french") and then he show me lines. So i think it doesn't come of the circuits. thanks for the helps

the code works but is not finishes.

#include<Keypad.h>
#include <LiquidCrystal.h>


const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
char keys[ROWS][COLS] = {
 {'*','0','#'},
 {'7','8','9'},
 {'4','5','6'},
 {'1','2','3'}
};
byte rowPins[ROWS] = {7,8,9,13}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {0, 1, 6}; //connect to the column pinouts of the keypad

int i, ages, poids, utilisateur1, reponse = 0, utilisateur2;
char prenom[20] = { 0 };
float densimetre, pourcentalcool, alcoolingere, volume = 33;

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal lcd(12,11,5,4,3,2);
char key = keypad.getKey();
void setup() {

 lcd.begin(16,2);
}

void loop(){
 char key = keypad.getKey();
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("bonjour");
 delay(1500);
 lcd.setCursor(0,1);
 lcd.print("etes vous");
 lcd.setCursor(0,2);
 lcd.print("l'utilisateur 1?");
 lcd.setCursor(0,3);
 valeurclavier();
 if (key =! NO_KEY){
   delay(1500);
   lcd.clear();
   lcd.print("Users 1");
   lcd.setCursor(0,4);
 }
 else{
   delay(3000);
   lcd.clear();
   lcd.print("users numbers?");
   lcd.setCursor(0,4);
   valeurclavier();
   delay(1500);
   lcd.print("users");
   lcd.print(key);
 }

}
void valeurclavier(){
 while( key == NO_KEY){
   char key = keypad.getKey();
   lcd.print(key);
 }
}

laneigeluge

this is the picture the hello is the second, and in first(picture) come the bug

groundFungus

Code: [Select]
void valeurclavier()
{
   while ( key == NO_KEY)
   {
      char key = keypad.getKey();
      lcd.print(key);
   }
}

This does not look right.  While there is no key get and print a key?   If you comment out the calls to valeurclavier() the display does not fill up with the bad characters.  Check the examples to see how to detect and receive a keypress.

Code: [Select]

lcd.setCursor(0,2);
lcd.setCursor(0,3);
lcd.setCursor(0,4);

Your display is 16 character - 2 lines.  There is no line 2, 3 or 4 only 0 and 1.  The syntax is lcd.setCursor(character_position, line).

Code: [Select]
if (key =! NO_KEY){
This is not the same as "if key not equal NO_KEY".  The order of ! and = matters.  Should be

Code: [Select]
if(key != NO_KEY)
I think.

Please read the "how to use this forum-please read" stickies to see how to properly post code.

laneigeluge

Thanks for all your comments, it's my first week in arduino, and i have much to learn!

bperrybap

You have 3 different variables all called key that are in different scopes.
One is declared as a global just below the lcd constructor.
The second is declared at the top of the loop() function
The 3rd is declared inside the valeuclavier() function.

While creating multiple different variables with the same name is allowed, in this case it does not seem to be what you are really wanting to do.

For example, this is a problem:

Code: [Select]
void valeurclavier(){
 while( key == NO_KEY){
   char key = keypad.getKey();
   lcd.print(key);
 }


The variable named key  in the while is not the same as the variable named key that is being declared and  assigned from keypad.getKey()
Once you enter that while loop, there is no way to ever leave since the while and the assignment are working with two different variables both named key

If you want a single global variable then just declare it once and then simply assign it rather than declare another one.
i.e.
This declares a new variable named key and assigns a value to it.
Code: [Select]
char key = keypad.getKey();

while this assigns a value to a variable named key that is declared somewhere else.
Code: [Select]
key = keypad.getKey();


--- bill



Go Up