Simplifying Function (combine string and int)

Hi All,

I’m trying to find a more elegant way to update my LCD and cursor position on the LCD.

The function here is just to illustrate something that I use to set the current cursor location, which I would like to simplify. Obviously this function is not useful as is (I have set up a switch case for each LCD.print), but I just want to move forward with a strategy and then apply it to my current code as needed.


cursor() {

1st revalation:

cursor() {
  char pos1 = "?x00?y0";
  char pos2 = "?x01?y0";
  char pos3 = "?x02?y0";


1st evolution (which I do not think will compile or work as I expect):

cursor() {
  char pos[33] = {"?x00?y0", "?x01?y0", "?x02?y0", ..., "?x15?y1"};
  for (int i = 0, i < 33, i++) {


for (int y=0; y<=1; y++)
  for (int i=0; i<=15; i++)
    if (i < 10)

You could also use sprintf() if you wanted to do a single LCD.print() call.

lcd.write() is useful sometimes, others not, just have to experiment. Here is something I threw together.

void cursor() {
  for (int i = 0; i < 2; i++) {
    lcd.print(i, DEC);
    for (int j = 0; j < 16; j++) {
      if (j < 10) {
      lcd.print(j, DEC);

Slightly redundant as it reprints the 0’s in for x and y both, but it gets the job done.

Note though, there is no delay in between each segment so it is pretty instantaneous. If you add any sort of delay in between each iteration of the for loop, it works like a gem.

Yup, looks like what Arrch posted would also get the job done, pretty much the same thing.

Somehow my last piece did not get copied to my post:

I think there is a way to do something with having an x and y variable, and somehow concatenate the string, but I’m not seeing it yet.

cursor() {
  for (int y = 0, y < 2, y++) {
    for (int x = 0, x < 16, x++) {
      LCD.print("?x" && char(x) && "?y" && char(y));

Note that I am not using a parallel LCD nor the liquid crystal library.

Arrch, I will try your proposal tonight. I suspected there wold be an issue with the line endings when splitting up the command.

BTW, this is a modern device LCD with a serial interface (pic chip).