Need Help with LCD and Keypad programming

03 Nov 2011

Hello guys

I am doing a project which will be using a keypad to enter number and character to a LCD display. However I encountered a problem which is that when I want to enter the 2nd character, it will overwrite with the 1st character. I believe is something wrong with my programming.

Here is my programming, I am a amateur programmer so I hope you guys can help me along.

  1. include "mbed.h"
  2. include "TextLCD.h"
  3. include "keypad.h"

DigitalOut myLed(LED1);

Keypad telepad(p28, p27, p26, p25, p24, p23, p22, p21);

TextLCD lcd(p15, p16, p17, p18, p19, p20);

int main (){

char key;

lcd.printf("Loading..."); wait(2); lcd.cls();

while (1) { key = telepad.getKey();

if (key != KEY_RELEASED)

lcd.printf("%c\n\n", key);

} }

03 Nov 2011

I suggest you position the "cursor" (ie the next character location) using the locate function of the TextLCD library, before you do a printf of your data.

Hope that helps.

Scott

04 Nov 2011

what you meant was to enter in

void TextLCD::locate(int column, int row) { _column = column; _row = row; }

to my program? I try it but it say I have some error.

04 Nov 2011

It makes it very hard to help you if you don't include the error message, however it looks like you are using the locate function incorrectly. Try something like this:

 // using a char variable
 lcd.locate(10,1);
 lcd.putc(char_variable_name);
 
 // using a text character
 lcd.locate(10,2);
 lcd.printf("L");

Scott

08 Nov 2011

Ok great! thanks a lot! anyway, just wondering, is there anyway that i could write a program such that when i enter * it will leave a spacing instead of entering the char?