Hi Emgee,
I've been playing too and have a similar problem. I'm pretty sure the issue is the bit of code that works out which key is being pressed. It's the very last function at the end of the Sketch and it looks like this:
int read_LCD_button() // routine to read the LCD's buttons
{
int key_in;
delay(ADSettleTime); // wait to settle
key_in = analogRead(0); // read ADC once
delay(ADSettleTime); // wait to settle
// average values for my board were: 0, 144, 324, 505, 742
// add approx 100 to those values to set range
if (key_in > 850) return NO_KEY;
if (key_in < 70) return RIGHT_KEY;
if (key_in < 250) return UP_KEY;
if (key_in < 450) return DOWN_KEY;
if (key_in < 650) return LEFT_KEY;
if (key_in < 850) return SELECT_KEY;
}
The way the code works is that pressing a key generates a voltage that's measured by the arduino. The voltages can vary between individual LCD boards. Mine generates voltages that don't quite line up with the values in the sketch. I get:.
- NO_KEY 1023 (This is OK)
- RIGHT_KEY 0 (This is OK)
- UP_KEY 99 (This is OK)
- DOWN_KEY 255 (This is only just OK)
- LEFT_KEY 409 (This is WRONG – the sketch thinks the DOWN_KEY has been pressed)
- SELECT_KEY 638 (This is WRONG – the sketch thinks the LEFT_KEY has been pressed)
Easily fixed. I change these lines in the function to read:
if (key_in > 850) return NO_KEY;
if (key_in < 70) return RIGHT_KEY;
if (key_in < 230) return UP_KEY;
if (key_in < 350) return DOWN_KEY;
if (key_in < 450) return LEFT_KEY;
if (key_in < 850) return SELECT_KEY;
You can use the IDE's monitor to find out what voltages are stored in key_in when the various buttons are pressed. To do this, add the command
Serial.begin(9600);
to the function called setup at the beginning of the sketch.
Then add Serial.println( key_in ) to the read_LCD_button function as shown:
int read_LCD_button() // routine to read the LCD's buttons
{
int key_in;
delay(ADSettleTime); // wait to settle
key_in = analogRead(0); // read ADC once
delay(ADSettleTime); // wait to settle
// average values for my board were: 0, 144, 324, 505, 742
// add approx 100 to those values to set range
Serial.println( key_in ); // for debugging
if (key_in > 850) return NO_KEY;
if (key_in < 70) return RIGHT_KEY;
if (key_in < 230) return UP_KEY;
if (key_in < 350) return DOWN_KEY;
if (key_in < 450) return LEFT_KEY;
if (key_in < 850) return SELECT_KEY;
}
Verify and Upload the sketch, then turn on the monitor with Tools->Serial Monitor. It may be necessary to set it to 9600 Baud. (bottom right of screen)
The monitor should start spewing the number 1023. When you press a button a different number will appear in the stream. This is the value your LCD Board uses to signal that key is pressed. Record the value produced by each key and compare it with the values in the Sketch, changing the sketch as necessary.
After you've got it working it's tidy to remove the Serial commands. The Sketch will still work if you leave them in.
Hope that makes sense!
Dave
Edited By SillyOldDuffer on 09/12/2016 17:03:14