lcd keypad

Hola, estoy intentando un programa en una arduino mega 1280 con un lcd keypad shield para seleccionar desde este ultimo una serie de 8 reles, o sea, mediante las teclas arriba/abajo selecciono un rele que puede ser del 1 al 8; mediante las teclas derecha/izquierda selecciono on/off, y la seleccion la hago con la tecla select, espero que alguien pueda ayudarme ya que me he quedado sin cerebro intentandolo, hasta ahora pude hacer andar el ldc y el teclado con esta compilacion

#include <LiquidCrystal.h>
//create object to control an LCD.
//number of lines in display=1
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//Key message
char msgs[5][15] = {"Derecha OK....",
"Arriba OK.....",
"Abajo OK......",
"Izquierda OK..",
"Seleccion OK.." };
int adc_key_val[5] ={30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;

void setup() {
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat

lcd.begin(16, 2);
//optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
//lcd.commandWrite(0x0F);//cursor on, display on, blink on. (nasty!)
lcd.clear();
lcd.print("GF Electricidad");

lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("Test de teclado");

}

void loop() {

adc_key_in = analogRead(0); // read the value from the sensor
digitalWrite(13, HIGH);
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)
{
oldkey = key;
if (key >=0){
lcd.setCursor(0, 1); //line=2, x=0
lcd.print(msgs[key]);
}
}
}

//delay(1000);
digitalWrite(13, LOW);

}

// 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;
}

las salidas que uso para los reles son: 21/23/25/27/29/31/33/35

desde ya gracias y espero que alguien pueda ayudarme.