First off thanks to adafruit for producing this excellent solution to getting user input and displaying on an LCD while minimizing the number of i/o ports needed on the Uno. I am using it as the user interface of a guitar vintage echo effects project.
Part of my project allows the user to enter an alphanumeric name for an effects patch by using the up and down buttons to change the current character in the name, the Select button to step on to the next character in the name and the right button to exit the routine with a string containing the complete name.
The code is contained in a while () loop and is working but, because the loop executes pretty fast, the character often jumps several letters before the user can remove their finger from the up or down button.
Apart from adding a delay in the while() loop is there any way to just accept single button presses and prevent the buttons from 'auto-repeating'?
I'd really appreciate any helpful suggestions
Phil.
This is the relevant section of my code ...
Code: Select all
void NameSong(void) {
// Here the code to allow the user to Enter a name for their patch/song
String song = " "; // Initialise to a blank name
int i = 0; // index into the song string
char c = 'A'; // current character being edited
boolean done = false;
int button = 0;
lcd.clear();
lcd.print(c);
done = false;
while (!done) {
lcd.setCursor(i,0);
button = lcd.readButtons();
if (button & BUTTON_UP) {
if (++c > 'Z')
c = 'Z';
lcd.print(c);
}
if (button & BUTTON_DOWN) {
if (--c < 'A')
c = 'A';
lcd.print(c);
}
if (button & BUTTON_SELECT) {
song.setCharAt(i, c);
lcd.print(c);
if (++i > 15)
i = 15;
c = 'A';
lcd.setCursor(i,0);
lcd.print(c);
}
if (button & BUTTON_RIGHT) {
song.setCharAt(i, c);
done = true;
}
delay(250); // Try to stop button 'auto-repeat'
}
for (i = 0; i < 16; i++)
UserPatch.name[i] = song.charAt(i);
}