Looking for a stylish way to read out a Keypad (Button-Matrix)
hallo, everyone.
i did few steps forward arduino , family in past. want go futher on , beauty inside code.
english isn't first language (maybe not second) , not programmer. indulgent - maybe - stupid problem:
i have keypad 60+ keys here. every key should send different line rs485-bus.
rs485 running, (including hardware) fine.
i made similar project 1 year ago 70 buttons arranged in 2 matrixes. button-presses read out switch-case monster, releases of buttons also.
in new project want prevent monster of cases cause it's crime debug
here short relevant detail of code (the rest isn't secret, want set focus):
expressions inside case doesn't make sense here without context, trust me: works.
i did not compile nor uploaded sketch avr. know run - last 1 did.
here problem or question:
do know (much) better way read out happens inside keypad?
as you'll see, small part of code changes. there 2 variables (which have declare somehow , somewhere).
i want prevent ugly swich-case-construction.
i know: while wrote post easy manage write 2x 60 lines of code. but: code has(!) beautiful.
thank in advance
dresi
i did few steps forward arduino , family in past. want go futher on , beauty inside code.
english isn't first language (maybe not second) , not programmer. indulgent - maybe - stupid problem:
i have keypad 60+ keys here. every key should send different line rs485-bus.
rs485 running, (including hardware) fine.
i made similar project 1 year ago 70 buttons arranged in 2 matrixes. button-presses read out switch-case monster, releases of buttons also.
in new project want prevent monster of cases cause it's crime debug

here short relevant detail of code (the rest isn't secret, want set focus):
code: [select]
...
#include <keypad.h>
const byte rows = 8; //eight rows
const byte cols = 9; //nine columns = 72 buttons ara available
char cdu[rows][cols] = { // upper-/lower-case matter!!!
{'1','2','3','4','5','6','7','8','9'},
{'0','a','b','c','d','e','f','g','h'},
{'i','j','k','l','m','n','o','p','q'},
{'r','s','t','u','v','w','x','y','z'},
{'a','b','c','d','e','f','g','h','i'},
{'j','k','l','m','n','o','p','q','r'},
{'s','t','u','v','w','x','y','z','/'},
{'%','&','(',')','=','?','ä','ö','ü'},
};
byte rowpins[rows] = {a6, a5, a4, a3, a2, a1, a0, 13}; //connect row pinouts of keypad
byte colpins[cols] = {12, 11, 10, 9, 8, 7, 6, 5, 4}; //connect column pinouts of keypad
keypad keypad = keypad( makekeymap(keys), rowpins, colpins, rows, cols );
void keypadevent(keypadevent osb){
switch (cdu.getstate()) { // gives pressed, hold or released
case pressed:
switch(keys) { // following commands fired unique if pressed
case '1': senddcsbiosmessage("cdu_0", "1"); break; // cdu 0
case '2': senddcsbiosmessage("cdu_1", "1"); break; // cdu 1
case '3': senddcsbiosmessage("cdu_2", "1"); break; // cdu 2
// here follow 60+ other case(s)
}
}
case released:
switch(keys) { // following commands fired unique if released
case '1': senddcsbiosmessage("cdu_0", "0"); break; // cdu 0
case '2': senddcsbiosmessage("cdu_1", "0"); break; // cdu 1
case '3': senddcsbiosmessage("cdu_2", "0"); break; // cdu 2
// here follow 60+ other case(s)
}
}
}
...
expressions inside case doesn't make sense here without context, trust me: works.

i did not compile nor uploaded sketch avr. know run - last 1 did.
here problem or question:
do know (much) better way read out happens inside keypad?
as you'll see, small part of code changes. there 2 variables (which have declare somehow , somewhere).
i want prevent ugly swich-case-construction.
i know: while wrote post easy manage write 2x 60 lines of code. but: code has(!) beautiful.
thank in advance
dresi
you have keys in array , seems when identify key press pretty easy generate big key pressed , generate command taking account getstate() status... 5 lines of code probably...
Arduino Forum > Using Arduino > Programming Questions > Looking for a stylish way to read out a Keypad (Button-Matrix)
arduino
Comments
Post a Comment