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<lim ; )
{
if(digitalRead(dw)==HIGH)
{
if(input[i]<'a')
input[i]='z';
if(input[i]>'z')
input[i]='a';
input[i]=input[i]+1;
delay(1000);
}
if(digitalRead(up)==HIGH)
{
if(input[i]<'a')
input[i]='z';
if(input[i]>'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.
setup()
code and the variables declaration. Finally, a description if your wiring would be nice too, in particular you did not mention if you use pullup or pulldown resistors.