There must be a better way

Hi everyone,
I am facing a bit of an issue, I am working with an old alcated 16x02 LED sign (alcatel 3BD19232AC for the curious) and wanted to revive it by hooking it up to an arduino.

I got it to work, i can print messages, change colors, move the cursor etc. That is where i hit my issue.

To move the cursor, I print this to the Serial port :

Serial.print("\x03");

This would move the cursor to the third character of the first row, or

Serial.print("\x1e");

moves the cursor to the fourteenth character of the second row.

I would like not to have the codes hardcoded, ideally make a function like this :

moveCursor(int row, int col);

that would move the cursor to the specified position. I have successfully done it...with a huge 100 lines switch() case: :confused: which, to me seems less than ideal.

Does anyone has a better way to do this ?

Try this:

void moveCursor(int row, int col)
{
Serial.print(char(row*16+col));  
}

void setup()
{
Serial.begin(115200);
moveCursor(1, 14);
}

void loop()
{
}

Thanks ! It works perfectly. Could you explain how the line

char(row*16+col)

works ? I am a little confused. how does it translate to "\x1e"?

The display is expecting a single byte with the row in the high nibble and the column in the low one. The string you were using amounts to the same thing but uses hex notation to do it.

Using integers and a cast to char to tell serial.print what to with it makes it easier to do in fewer lines of code.

1 Like

Or just:

Serial.write(row*16+col); 
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.