How to Modify a Character in an Array?

Below are the character arrays for a 4x20 LCD:

char mainr1[] = ("      MAIN MENU     ");
char mainr2[] = (">PAGE 1             ");
char mainr3[] = (" PAGE 2             ");
char mainr4[] = (" PAGE 3             ");

I would like to modify these characters as the user navigates a menu using pushbuttons. For instance, as the user moves down the menu, the > symbol would need to move down each row like this:

char mainr1[] = ("      MAIN MENU     ");
char mainr2[] = (" PAGE 1             ");
char mainr3[] = (">PAGE 2             ");
char mainr4[] = (" PAGE 3             ");

and.......

char mainr1[] = ("      MAIN MENU     ");
char mainr2[] = (" PAGE 1             ");
char mainr3[] = (" PAGE 2             ");
char mainr4[] = (">PAGE 3             ");

and vice versa.

I am attempting to do it this like this, but a compile error is shown:

char mainr2[0] = " ";
//and
char mainr3[0] = ">";
//Error: initializer-string for array of chars is too long

Any ideas?

char mainr2[0] = " ";
//and
char mainr3[0] = ">";

Try it with single quortes around the characters.

Seems it might be easier to print/erase the pointer right on the LCD

To change a character, use assignment and a character:

  mainr3[0] = '>';

Your statements are incorrect declarations, we need to see some context.

a7

1 Like

Why not simply lcd.setCursor( 0, line ) and lcd.write( '>' ) ?

Of course, when the user select another line, you have to do lcd.write( ' ' ) before moving the cursor, to erase the previous '>'

Tried it with single quotes:

char mainr2[0] = ' ';
char mainr3[0] = '>';

Now getting the error: array must be initialized with a brace-enclosed initializer

Because I'm using an LCD based on the US2066 driver and it doesn't seem like it would be compatible with the LyquidCrystal library :frowning:

Single Quotes seemed to have worked without the char declaration:

mainr2[0] = ' ';
mainr3[0] = '>';

How can it now return back to the default declarations? @alto777

Those arrays are declared somewhere, and maybe initialised.

Later, you can read and write them at the character level using assignment, as you have discovered.

Things are declared in one place. Then used as promised by that declaration everywhere.

a7

1 Like

This library have a cursor method : GitHub - pedro11x/Arduino-US2066-OLED: wide.HK 1602 OLED Library

We are currently using the display in 8-bit parallel mode, so will need to reconfigure the setup for I2C to try and use this library. Any ideas on how to make a multi-layered menu with this display? I'll reference the other post here for the details: LCD Sub-Menu Functions with 4x20 OLED? - #85 by ironmarvel

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