Hey
Sorry guys. I never received a topic reply for some reason even though I selected to be notified.
Heres what I am trying for and what I have found so far.
I have used the below code to get the analog values from my lcd shield
/*************************************************************************************
Mark Bramwell, July 2010
This program will test the LCD panel and the buttons.When you push the button on the shield?
the screen will show the corresponding one.
Connection: Plug the LCD Keypad to the UNO(or other controllers)
**************************************************************************************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int a=0;
int bkl = 6;
byte bklIdle = 10;
byte bklOn = 100;
int bklDelay = 10000;
unsigned long bklTime = 0;
void setup()
{
pinMode(bkl, OUTPUT);
digitalWrite(bkl, HIGH);
lcd.begin(16, 2);
pinMode(A0, INPUT);
}
void loop()
{
a = analogRead(0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" analogRead() ");
lcd.setCursor(0,1);
lcd.print(" value is :");
lcd.print(a);
delay(250);
}
I then used the following code and modified the values to match my analog values on this line "int adc_key_val[5] ={0, 99, 257, 409, 643 };"
It works well but for some reason I could never get the select key to register
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char msgs[5][16] = {"Select Key OK ",
"Right Key OK ",
"Up Key OK ",
"Down Key OK ",
"Left Key OK" };
int adc_key_val[5] ={0, 99, 257, 409, 643 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
void setup()
{
pinMode(A1, OUTPUT); // analog 1 to digital 15
digitalWrite(A1, HIGH);
pinMode(A2, OUTPUT); // analog 2 to digital 16
digitalWrite(A2, HIGH);
pinMode(A3, OUTPUT); // analog 3 to digital 17
digitalWrite(A3, HIGH);
pinMode(A4, OUTPUT); // analog 4 to digital 18
digitalWrite(A4, HIGH);
lcd.clear();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("ADC key testing");
}
void loop()
{
adc_key_in = analogRead(0); // read the value from the sensor
key = get_key(adc_key_in); // convert into key press
if (key != oldkey) // if keypress is detected
{
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)
{
lcd.setCursor(0, 1);
oldkey = key;
if (key >=0){
lcd.print(msgs[key]);
}
}
}
delay(100);
}
// 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])
{
return k;
}
}
if (k >= NUM_KEYS)k = -1; // No valid key pressed
return k;
}
The following is the code I am trying to use but with ADC buttons on the shield instead of a dedicated board