Getting lcd.printf to work reliably inside a condition.

06 Apr 2010 . Edited: 06 Apr 2010

Hi all, I've been running some code to get a variable 'symbol', read from a PS2 keyboard, to print to a TextLCD (I'm using that library).

However, I want this to only happen when the char count of the array that's also being filled is under 20.

I'm using the following to put the current symbol into the next space in the array.

 

if (charcount <= maxmessage)

{

message[charcount] = symbol;

charcount++;

}

Now, I want to insert lcd.printf("%c", symbol) somewhere, to print the char to the screen as it's struck. Now, when put before the if, the chars all write consecutively on the screen, perfectly. However, if I put it as is shown below, only the first keystroke pops up on the display and the rest of the display stays blank. Can anybody tell me why please?

 

if (charcount <= maxmessage)

{

lcd.printf("%c", symbol);

message[charcount] = symbol;

charcount++;

}

 

Thanks a lot,

Simon