Need help to set row position of LCD cursor based on character in array[]

I’m trying to set the lcd cursor row to either 0 or 1, based on a character in an array. i.e.:

char MyArray[17] = “1xxxxxxxxxxxxxxx”;

I want to do something like this:

lcd.setCursor(0, int(MyArray[0]) );

I can’t seem to convert MyArray[0] into anything lcd.setCursor() can understand. I’ve tried declaring ints outside of the setCursor() and casting char(), byte() and more without success.

Any help would be greatly appreciated.

Thanks,
Jake

MyArray[0] is a char containing a '1', in your sample . If you subtract a '0', you get a 1, which is probably what you want.

There's a difference between a char '0' ( which is a decimal 48, btw ) and a 0 ...

Thanks Michael! That worked:

lcd.setCursor(0, MyArray[0]-'0' ); lcd.print(MyArray);

Regards, Jake

As you are going to become a c expert soon, you might be interested that both

  lcd.print(MyArray+1);
  lcd.print( & MyArray[1] );

will omit your first row indicator character, if you do not need to see it ; )

Nice!

I actually have my row indicator to position 17 in the array, then truncate it down to the 16 chars which will fit on my 16x2 LCD.

I had put the row indicator at the beginning of the array in my example to make it easier (for me) to explain :)

Thanks Michael!