![](/media/cache/profiles/d707329bece455a462b58ce00d1194c9.50x50_q85.jpg)
keypad.cpp@0:74b4b9fc9480, 2010-06-04 (annotated)
- Committer:
- alex89
- Date:
- Fri Jun 04 10:23:46 2010 +0000
- Revision:
- 0:74b4b9fc9480
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex89 | 0:74b4b9fc9480 | 1 | #include "main.h" |
alex89 | 0:74b4b9fc9480 | 2 | |
alex89 | 0:74b4b9fc9480 | 3 | int getKeyNum(){ |
alex89 | 0:74b4b9fc9480 | 4 | |
alex89 | 0:74b4b9fc9480 | 5 | DigitalIn col1(p18); |
alex89 | 0:74b4b9fc9480 | 6 | DigitalIn col2(p20); |
alex89 | 0:74b4b9fc9480 | 7 | DigitalIn col3(p16); |
alex89 | 0:74b4b9fc9480 | 8 | |
alex89 | 0:74b4b9fc9480 | 9 | DigitalOut row1(p19); |
alex89 | 0:74b4b9fc9480 | 10 | DigitalOut row2(p14); |
alex89 | 0:74b4b9fc9480 | 11 | DigitalOut row3(p15); |
alex89 | 0:74b4b9fc9480 | 12 | DigitalOut row4(p17); |
alex89 | 0:74b4b9fc9480 | 13 | |
alex89 | 0:74b4b9fc9480 | 14 | row1 = 1; |
alex89 | 0:74b4b9fc9480 | 15 | row2 = 0; |
alex89 | 0:74b4b9fc9480 | 16 | row3 = 0; |
alex89 | 0:74b4b9fc9480 | 17 | row4 = 0; |
alex89 | 0:74b4b9fc9480 | 18 | |
alex89 | 0:74b4b9fc9480 | 19 | if (col1) |
alex89 | 0:74b4b9fc9480 | 20 | return 1; |
alex89 | 0:74b4b9fc9480 | 21 | else if (col2) |
alex89 | 0:74b4b9fc9480 | 22 | return 2; |
alex89 | 0:74b4b9fc9480 | 23 | else if (col3) |
alex89 | 0:74b4b9fc9480 | 24 | return 3; |
alex89 | 0:74b4b9fc9480 | 25 | |
alex89 | 0:74b4b9fc9480 | 26 | row1 = 0; |
alex89 | 0:74b4b9fc9480 | 27 | row2 = 1; |
alex89 | 0:74b4b9fc9480 | 28 | row3 = 0; |
alex89 | 0:74b4b9fc9480 | 29 | row4 = 0; |
alex89 | 0:74b4b9fc9480 | 30 | |
alex89 | 0:74b4b9fc9480 | 31 | if (col1) |
alex89 | 0:74b4b9fc9480 | 32 | return 4; |
alex89 | 0:74b4b9fc9480 | 33 | else if (col2) |
alex89 | 0:74b4b9fc9480 | 34 | return 5; |
alex89 | 0:74b4b9fc9480 | 35 | else if (col3) |
alex89 | 0:74b4b9fc9480 | 36 | return 6; |
alex89 | 0:74b4b9fc9480 | 37 | |
alex89 | 0:74b4b9fc9480 | 38 | row1 = 0; |
alex89 | 0:74b4b9fc9480 | 39 | row2 = 0; |
alex89 | 0:74b4b9fc9480 | 40 | row3 = 1; |
alex89 | 0:74b4b9fc9480 | 41 | row4 = 0; |
alex89 | 0:74b4b9fc9480 | 42 | |
alex89 | 0:74b4b9fc9480 | 43 | if (col1) |
alex89 | 0:74b4b9fc9480 | 44 | return 7; |
alex89 | 0:74b4b9fc9480 | 45 | else if (col2) |
alex89 | 0:74b4b9fc9480 | 46 | return 8; |
alex89 | 0:74b4b9fc9480 | 47 | else if (col3) |
alex89 | 0:74b4b9fc9480 | 48 | return 9; |
alex89 | 0:74b4b9fc9480 | 49 | |
alex89 | 0:74b4b9fc9480 | 50 | row1 = 0; |
alex89 | 0:74b4b9fc9480 | 51 | row2 = 0; |
alex89 | 0:74b4b9fc9480 | 52 | row3 = 0; |
alex89 | 0:74b4b9fc9480 | 53 | row4 = 1; |
alex89 | 0:74b4b9fc9480 | 54 | |
alex89 | 0:74b4b9fc9480 | 55 | if (col1) |
alex89 | 0:74b4b9fc9480 | 56 | return -2; |
alex89 | 0:74b4b9fc9480 | 57 | else if (col2) |
alex89 | 0:74b4b9fc9480 | 58 | return 0; |
alex89 | 0:74b4b9fc9480 | 59 | else if (col3) |
alex89 | 0:74b4b9fc9480 | 60 | return -3; |
alex89 | 0:74b4b9fc9480 | 61 | |
alex89 | 0:74b4b9fc9480 | 62 | row1 = 0; |
alex89 | 0:74b4b9fc9480 | 63 | row2 = 0; |
alex89 | 0:74b4b9fc9480 | 64 | row3 = 0; |
alex89 | 0:74b4b9fc9480 | 65 | row4 = 0; |
alex89 | 0:74b4b9fc9480 | 66 | |
alex89 | 0:74b4b9fc9480 | 67 | return -1; |
alex89 | 0:74b4b9fc9480 | 68 | } |