Simple Text input using 5 buttons So I have to get this function done but I'm not so bright and got confused. 
(excuse me! I'm total noob)

The function is basically inputing text using five buttons, directional buttons and an ok button. The up and down buttons will be used to cycle through letters (a-z), and the left and right buttons will be used to control which array to cycle letters.

The control will be:


up button (up): ASCII-1 (z, y, x...)
down button (dw): ASCII+1 (a, b, c...)
right button (ri): array[i] ~> i+1 (go to next character/array)
left button (le): array[i] ~> i-1 (go to previous character/array)
ok button (ok): confirm text and changes the limit to stop function looping


I can't get it work with this code I write.


void intext()
{
  int lim=16;
  lcd.setCursor(0,1);
  lcd.print(input);
  for(i=0; i&lt;lim ; )
  {
    if(digitalRead(dw)==HIGH)
    {
      if(input[i]&lt;'a')
        input[i]='z';
      if(input[i]&gt;'z')
        input[i]='a';
      input[i]=input[i]+1;
      delay(1000);
    }
    if(digitalRead(up)==HIGH)
    {
      if(input[i]&lt;'a')
        input[i]='z';
      if(input[i]&gt;'z')
        input[i]='a';
      input[i]=input[i]-1;
      delay(1000);      
    }
    if(digitalRead(ri)==HIGH)
    {
      delay(1000);    
      i=i+1;
    }
    if(digitalRead(le)==HIGH)
    {
      delay(1000); 
      i=i+1;
    }
    if(digitalRead(ok)==HIGH)
    {
      lim=i+1;
      delay(1000); 
    }
  }
}

void loop()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Type your text:");
  intext();
  lcd.setCursor(0,0);
  lcd.print("Success!!");
  lcd.setCursor(0,1);
  lcd.print(input);
}


The result I wanted it to be is like this:
first you got the "type your text:" on the first row and blank in the second row.
our cursor is in the first column of the second row, so we can cycle through the alphabet letters. if you press right you can edit the next column of second row. you can get to the previous column in second row by pressing left. you can input up to 15 characters.
after done typing pressing ok will stop the typing and you will see "Success!!" in the first row and typed text in the second row.

Please help. I'm stumped.
Thank you.
Several issues in the code you posted:


Every change to the text you do inside the for loop, will not be reflected to the LCD until the for loop will end (when i&lt;limit will no longer be a true statement). You might want to add an additional code, inside the for loop and outside any of its conditional statements, that will repeatedly set the cursor and print input to the LCD. Something similar to the code you have prior to the for loop:

void intext() 
{
  ... // rest of the code until the for loop

  for (int i; i&lt;limit; ) 
  {
    ... // all the conditions for up/down/left/right/ok

    lcd.setCursor(0,1);
    lcd.print(input);
  }
}

Another problem is that when the user clicks left, the counter should be decremented, not incremented, and you should check for left boundary:

if(digitalRead(le)==HIGH &amp;&amp; i&gt;0) // left boundary check added
{
   delay(1000); 
   i=i-1; // and not i=i+1;

}

After clicking Ok, and since the for loop does not increment i, the condition in the for loop (i&lt;limit) will stay true, and the loop will not end until the user will click Right once more. To mitigate this, change the following

if(digitalRead(ok)==HIGH)
{
  lim=i; // and not: lim=i+1;
  delay(1000); 
}



Otherwise, the user will have to click Right for completion, to increment i once more. 


jfpoilpret comment about pull up/down is very important. Make sure you use pull up/pull down resistors in order to prevent input debounce (more details inside this link).