Hello,
So I am trying to write a code that checks if a specific coordinate on a LCD screen has something written in it. Does it exist. If so anyone help me out.
Thank You,
Jack
Hello,
So I am trying to write a code that checks if a specific coordinate on a LCD screen has something written in it. Does it exist. If so anyone help me out.
Thank You,
Jack
Of course such a thing can be written. But what would the use of such a thing be, since any program that writes data to the screen MUST know what it wrote there. That is why most drivers don't have it.
So what is happening is that I am using lcd.setCursor(y,x) to generate random places on the screen for various letters, but I don't want (if the random generator produced the same x, y values twice) the program to write over what was previously there. I want the program to check if there is something there and if so it should make a new random set. If it is empty then I want it to enter the letter.
If that makes any sense.
Thanks again.
Depends on the LCD. Most controllers I have seen have commands to set up an address and then read and write from DD (data display) RAM. Questions are: is it in a graphics mode or a text mode? What is the memory layout? Some LCD's split a 4 line character display into two separate memory spaces. If in text mode it could be simply accessing a DD RAM location based on the character position (10th character addressed at memory location hex 0x09, for instance). If it's in graphics mode, what is the resolution? how is the memory mapped? Some are character mapped. Which means the first 8-10 bytes are stacked in the upper left corner, then it goes back to the top and another 8-10 bytes -- that is a real pain to calculate an X,Y position from. In both memory and character mapping you have to calculate an x and y position differently for different resolutions and character map sizes. A 320 horizontal by 240 vertical memory mapped color screen might have a pixel at an x and y of (10,14), in which case you have to do something like ((y-1)*340)+x to get the actual memory location of the dot.
Basic 16x2 Character LCD - White on Black 5V - LCD-00709 - SparkFun Electronics Here is the type of LCD display it is.
Thank you
You didn't mention the library, so I went all low-level code... sorry.
Aside from going low-level into hand-coding for the LCD, you apparently have to keep track of it yourself with an array. You'd have to write a function that loads something like
byte usedLoc[4][20];
then look in the array to make sure it's empty at that y,x. If not, put the character out and also put it in the array at that y,x.
Unless your lib has a getCursor(y,x); function...
Okay that's a 16X2 so it should be fine to use something like
char usedLoc[2][16];
and something like (I have not actually tried this... since I don't have that lcd
)
void fillARand(char rndChar, byte yPos, byte xPos) {
lcd.setCursor(yPos,xPos);
if (usedLoc[yPos][xPos] == ' ') {
//write the char - is it lcd.print(rndChar); ?
//write to the array
usedLoc[yPos][xPos] = rndChar;
}
}
and in setup() you'll probably need a couple of for loops to set all the array elements to a space character...