ROM code is fixed and supposed to be printed on the chip, but these blob chips have nothing printed.
I played around and hacked a working code into a character lookup thingy:
/*
Sloppy hack of the LcdKeyShield code i found somewhere
Meant to lookup the characters and their codes using the LcdKeyShield (this one is DFRobot compatible)
The circuit:
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD BL pin to digital pin 10
* KEY pin to analog pin 0 (14) THIS IS THE BUTTON PIN
*/
#include <LiquidCrystal.h>
//Old LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char msgs[5][16] = {"Right Key OK ",
"Up Key OK ",
"Down Key OK ",
"Left Key OK ",
"Select Key OK" };
//int adc_key_val[5] ={1, 150, 500, 350, 800 }; // 1st change
//int adc_key_val[5] ={800, 500, 350, 150, 50 }; // Original inverted order
int adc_key_val[5] ={50, 200, 400, 600, 800 }; //Original, works after actually reading the analog0
//int adc_key_val[5] ={ 0, 133, 308, 482, 723 };// Had to change the order of the keys to have them show up correct.
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
int i=1;
void setup()
{
Serial.begin(9600);
lcd.clear();
lcd.begin(16, 2);
lcd.setCursor(0,0);
// lcd.print("ADC key testing");
lcd.print("< Char lookup >");
}
void loop()
{ //1
key = (analogRead (0));
//Serial.println(analogRead(0));
if (key != oldkey) // if keypress is detected "!=" means not equal!!
{//2
delay(50); // wait for debounce time
adc_key_in = analogRead(0); // read the value from the sensor
key = get_key(adc_key_in); // convert into key press
if (key != oldkey)
{//3
lcd.setCursor(0, 1);
oldkey = key;
if (key >=0){//4
//lcd.print(msgs[key]);
Serial.println(key);
Serial.println(analogRead(0));
if (key == 308)
{
Serial.println(" down ");
}
if ((key)==3) i--;
if ((key)==0) i++;
if ((i)==256) i=1;
if ((i)==0) i=255;
lcd.setCursor(1,1);
lcd.print(i);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.write(i);
}//4
}//3
}//2
/*
if (key = 800)
{
delay(2000);
lcd.clear();
}
*/
delay(100);
}//1
// Convert ADC value to key number
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
{
//if (input == adc_key_val[k]) //works
if (input < adc_key_val[k]) // should be more reliable as it doesn't looks for a range instead of a fixed value but it isn't
{
return k;
}
}
if (k >= NUM_KEYS)k = -1; // No valid key pressed
return k;
}
As stated, it's a bit sloppy but it works.
Use the left and right keys to go back or forth.
How about characters # 247, 249, 244 and 228 ?