Hello again everybody. I've recently made a post about my problem but still couldn't solve it. Here is a better explanation of it with more detailed codes.
I have a DFRobot LCD Shield (16x2) and I'm trying to input text using the five buttons on the lcd; directional buttons and select 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.
I have found a code and modified it according to my hardware. However, it is not working at the moment. The problem is once I upload it to my Arduino, all I see on the LCD is the letter 'a' on the bottom row and that's it. The buttons do nothing and I'm not sure what the problem is. The code is below, I would really appreciate it if someone could tell me what's wrong
Hi, the program should always be in textinput function. Should I be adding something else to the loop? Shouldn't the screen at least be showing "Enter Your Text" on the screen when I run it? Sorry if the questions are silly, I have a limited knowledge.
bgozneli:
Hi, the program should always be in textinput function. Should I be adding something else to the loop?
For an interactive program that has to react quickly on any human input, you'd better forget completely about the delay() function! The delay() function will block the program execution for some time. Blocking the execution of your program for some time is something you surely not want when you want to enter some text quickly and hassle-free.
Usage of the delay() function in the sketch makes the program clumsy and nearly useless for human interaction.
A couple of days ago I developed a button 'state change' detection for the type of analog buttons available with the LCD keypad shield. The function will only return the button code when the state of a button changes from 'no button pressed' to 'button pressed'.
Here is the code:
enum {btnNONE, btnSELECT, btnLEFT, btnRIGHT, btnDOWN, btnUP};
int readButtonInput() // read the button state change 'pressed' from analog interface
{
static int lastValidKey=btnNONE;
static boolean waitForNONE;
int currentKey;
int adcValue[3];
for (int i=0;i<3;i++) // read pin three times
{
adcValue[i] = analogRead(A0); // read the ADC value from A0
}
if (abs(adcValue[1]-adcValue[0])>1 || abs(adcValue[2]-adcValue[0])>1)
{
return btnNONE; // return because invalid input (reading is too much different)
}
if (adcValue[0] > 1000) currentKey= btnNONE;
else if (adcValue[0] < 70) currentKey= btnRIGHT;
else if (adcValue[0] < 235) currentKey= btnUP;
else if (adcValue[0] < 410) currentKey= btnDOWN;
else if (adcValue[0] < 620) currentKey= btnLEFT;
else if (adcValue[0] < 880) currentKey= btnSELECT;
else return btnNONE; // when all others fail, return because invalid input
if (currentKey==btnNONE)
{
waitForNONE=false;
lastValidKey=btnNONE;
return btnNONE;
}
else if (waitForNONE==false)
{
waitForNONE=true;
lastValidKey=currentKey;
return currentKey;
}
return btnNONE;
}
You can use that to create menu control or text input without any delay().
Please let me know if you need further assistance.