Skip to content

Characters and arrays in Arduino C

I attempted to update the data structure described in the previous post to create a 3D array of characters.  I learned that Arduino C has a library to support strings, and so I changed my previously used character arrays in to strings:

String menuitems[5][4]={
{menu00, menu01, menu02, menu03},
{menu10, menu11, menu12, menu13},
{menu20, menu21, menu22, menu23},
{menu30, menu31, menu32, menu33},
{menu40, menu41, menu42, menu43}

I also changed the names of the strings slightly to make more sense when referencing them.  I then changed the purpose of the “ok” button to be more of a “redraw” button, taking the menuLevel from the option currently selected by the up/down buttons.

  int i=0;
lcd.setCursor (0,0);
lcd.setCursor (1, i);

This worked for the first menu (main menu) and then part of the Flight Control menu.  After this point however, it would output unexpected nonsense values.  With the help of a colleague we discovered that although Arduino C will allow you to declare an array in the method seen above, it does not actually function correctly.  As a result, the 3D array was changed to multiple arrays linked together with the use of pointers.

char* menu0[] = {“Main Menu”, “Flight Control”, “Waypoints”, “Power”};
char* menu1[] = {“Flight Mode”, “Up/Down Mode”, “Move Mode”, “Metrics”};
char* menu2[] = {“Drop Control”, “Open/Drop”, “”, “Metrics”};
char* menu3[] = {“Waypoints”, “Waypoint 1”, “Waypoint 2”, “Metrics”};
char* menu4[] = {“Power”, “Controller Power”, “UAV Power”, “Metrics”};

char** menuitems[] = {menu0, menu1, menu2, menu3, menu4};

At the suggest of my colleague, the contents of the menu items have also been included at this stage, without the space characters that previously caused me issues.  lcd.clear() has been invoked to clear out the previous characters to counter this.

Published inBSc Dissertation

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *