analog debounce buttons not working in order

My project is using a adb 5 button module to mimic the lcd shield buttons the problem im having is the buttons Im using are not going in same order as the shield buttons eg ( 30,170,390,600,800 ) my button module values are ( 0, 142, 329, 506, 743) so when i add my values to the sketch they dont work in the order they should like right button will be up left will be select etc anyone had similar problem ?

code:

int adc_key_val[5] ={ 0, 142, 329, 506, 743 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;

if ((keypress == 0) Right
if ((keypress == 1) Up
if ((keypress == 2) Down
if ((keypress == 3) Left
if ((keypress == 4) Select

My button order:

Button 0 = Left
Button 1 = Up
Button 2 = Down
Button 3 = Right
Button 4 = Select

lumbergnz:
My project is using a adb 5 button module to mimic the lcd shield buttons the problem im having is the buttons Im using are not going in same order as the shield buttons eg ( 30,170,390,600,800 ) my button module values are ( 0, 142, 329, 506, 743) so when i add my values to the sketch they dont work in the order they should like right button will be up left will be select etc anyone had similar problem ?

Translate.

int fixkeypress( int a){
   int table[]={3,1,2,0,4};
return table[a];
}

Everyplace in your code where keypress is called replace it with fixkeypress(keypress)

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

Thankyou chucktodd sorted it :slight_smile: