SlimeDont5:
Also would you explain a bit to point of this ? I am trying to understand it but its kinda diffucult. We are clearing the value because they are stacking on each other but i am missing something on that point.
In the LCD library is a function called drawChar which is used when you want to put an ASCII character on the screen. The part that actually draws the pixel(s) looks like this:
for (int i =0; i<FONT_X; i++ ) {
INT8U temp = pgm_read_byte(&simpleFont[ascii-0x20][i]);
for(INT8U f=0;f<8;f++)
{
if((temp>>f)&0x01)
{
fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
}
}
}
Basically, if the character you're drawing needs a pixel turned on at a given location, it will do that by drawing a rectangle at that location. However, if the character you're drawing needs a pixel turned off at a given location, it doesn't do that (and there may be very good reasons the authors omitted that.) To do so it might look like:
for (int i =0; i<FONT_X; i++ ) {
INT8U temp = pgm_read_byte(&simpleFont[ascii-0x20][i]);
for(INT8U f=0;f<8;f++)
{
if((temp>>f)&0x01)
{
fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
}
else
{
fillRectangle(poX+i*size, poY+f*size, size, size, bgcolor);
}
}
}
Note the "else" there now: if a pixel in the character is '0', draw a rectangle the same color as the background at that location. (Unfortunately, there doesn't even appear to be a "bgcolor" variable so this is just demonstrative.) This will have the effect of clearing that pixel on the TFT. So if the characters are all built using the same x-y size bitmaps, writing a new one would automatically erase the old ones.
Because that capability isn't written in the library, you basically need to erase the characters yourself. This means writing the character twice; once to show it and then, later, again -- using the BLACK background color -- to turn off all the pixels that were turned on previously. Then you draw your new character.
I use "lastx" and "lasty" to track the value that was written. This serves two purposes; first, it allows us to erase what was there as described, but it also reduces the amount of time you spend drawing elements on the screen. For example, if the value of 'y' has not changed there's no need to draw it again.