This is my first attempt at writing a function as well as an ISR.
I have a 4x3 membrane keypad that looks exactly like this:
It has the standard "pin-1" arrow on the rightmost pin of the connector with the keypad right side up.
The 74c922 keypad encoder ic is breadboarded with the keypad and leds display the status of the
4 output pins (OUTA-pn17,OUTB-16,OUTC-15,& OUTD-14), as well as DATA_AV-pn-12.
With OE-NOT tied LOW to ground , the keypress data is latched at the output and displayed on the leds.
I am not certain that I have the four ROWS (Y1,Y2,Y3,Y4) and three columns (X1,X2,X3,) connected
correctly but that can wait till later. The 74c922 is a 16-key encoder, NOT 12 , and I THOUGHT I had
ordered a 4x4 keypad but in my haste actually ordered a 4x3. I have a 4x4 on order . I also ordered a
TCM5089 12-KEY keypad encoder IC and xtal as well. My problem right now is that my ISR is clearly
not working. I have attached two files, one that compiles and one that does not. It seems my
problem is that the ISR should return the value (val) from convering the BCD (I think) to an integer.
I know there must be functions and libraries already written to read a simple BCD encoded value
but they look very much like this:
so I adapted this "readSwitch" and changed the function name (that's plagarism isn't it ? yeah, so what?)..
I looked on the forum for how to write a function (here)
but I'm stuck on whether or not the ISR should have the name of the variable it is returning with
in the parenthesis:
ie:
int readEncoder(total) <===(LIKE THIS)
{
int total=0;
if (digitalRead(OutA)==HIGH) { total+=1; }
if (digitalRead(OutB)==HIGH) { total+=2; }
if (digitalRead(OutC)==HIGH) { total+=4; }
if (digitalRead(OutD)==HIGH) { total+=8; }
return total;
}
The Tronixstuff code does NOT so I left it out.
In any case the program that compiles just returns "0" always, and the other program doesn't compile
so I think I am close but am missing something obvious that anyone with experience would know.
Can anyone help me ?
If I can get it to return some value then I can find address the other issue of why the BCD isn't correct.
The TRUTH TABLE for circuit now is the following;
KEY: D,C,B,A=>DECIMAL
1: L,L,L,L=> 0
2: L,L,L,H=> 1
3 : L,L,H,L=> 2
4: L,H,L,L=> 4
5: L,H,L,H=> 5
6: L,H,H,L=> 6
7: H,L,L,L=> 8
8: H,L,L,H=> 9
9: H,L,H,L=> 10
0: H,H,L,H=> 13
*: H,H,L,L=> 12
#: H,H,H,L=> 14
As you can see, the decimal values omit 3, & 7.
(0,1,2,4,5,6,8,9,10,13,12,14)
and "12" & "13" are swapped.
I have attached:
- a photo of the keypad with the adhesive cover paper removed.
- a screenshot of the IDE complile error. (I still can't figure out how anyone can copy the compiler output when
the right-click /copy menu doesn't open when you right click. - the program that compiles ok but always returns "0"
- the program with the compile error
keypad_4x3_COMPILES_ERROR_2.ino (938 Bytes)
keypad_4x3_COMPILES_OK.ino (1.13 KB)