You guys crack me up.
I realize the diodes are not needed but it makes a better mouse trap .
I understand the module after I followed the code flow and the need for the diodes but why not include them. It does make a better key pad.
I admit I tend to jump the gun and assimilate bits and pieces then ask why.
That's why I assemble bits of code, test that snippet then AFTER all the snippets work as planned, I put the entire puzzle together into one package.
The keypad is the first snippet then get the LCD working then hopefully get both to play together nice.
No. More, unnecessary parts do not make a "better mouse trap", particularly where it is likely that they won't be added correctly. Sorry MrDEB, your history here attests to that fact.
MrDEB is trying to make a calculator, to add up domino values. As such, there is no reason multiple keys will be pressed at the same time and therefore, no problem with ghosting.
Don't make it more difficult than it needs to be, especially when doing so enhances nothing.
Well if he had read the whole post that he linked the diodes don't make up for bad coding. I tried them out didn't really make anything better that was using the keypad bas
They don't make for bad coding, if they are installed correctly. They add nothing for this app and increase the likelihood of errors substantially.
With about 10 minutes of effort, I came up with this program, which reads keys as expected.
Code:
Include "keypad16pullup.bas"
Include "usart.bas"
Include "convert.bas"
Dim Keypressed As Byte
Dim Keyvalue As Byte
SetBaudrate(br9600)
DelayMS(5000)
USART.Write ("Test program",13, 10, 10)
While 1 = 1
Keypressed = keypad16.Value
If Keypressed <> 0 Then
USART.Write ("Key pressed = ", HexToStr(Keypressed), 13, 10)
End If
Wend
The output looks like this. It prints out a value as long as a key is pressed.
Burt, I haven't really looked at where the diodes should go. I suspect there are different methods. But since they aren't necessary for this application, they can't improve anything; they can only screw things up. So why have them?
Here's a picture of the keypad I used. The 4×4 matrix is completely isolated from the other switches and LEDs. Nothing but 16 switches comnected to rows and columns. And NO DIODES.
As far as telling when a new switch is pressed, look for a value of 0. That indicates no switch is pressed.
Burt,
What you and MrDEB posted both had the diodes in the same place - in series with the push buttons. When you said they were wrong I mistook the green arrow in your diagram as a diode.
Mike, I think diodes are going to add 5 by themselves!
It's weird to me that someone who won't spend 27 cents to use a crystal and who is complaining how crowded his board is would be so reluctant to not include diodes where they aren't needed. Such are the mysteries of life.
The diodes are wrong there not going to fix the problem and your right i looked at the link he posted he has them drawn different.
But its the same but i was more thinking adding them. Not going to help lol
Here's a slight addition to my code to read each keypress only once until the key has been released. Holding the key down does not result in another keypress being recorded. I am printing out the hex value of each key, pressed in order. For whatever reason, $10 comes out of order after $F. I'm not sure if this is a problem in the keypad module or in the keypad hardware. At any rate, this won't be a problem for MrDEB, as he needs to map the keypress value against what he wants for the value of each key.
This is still a tiny amount of code to read the keypad.
Code:
Include "keypad16pullup.bas"
Include "usart.bas"
Include "convert.bas"
Dim Keypressed As Byte
Dim Keyvalue As Byte
SetBaudrate(br9600)
DelayMS(5000)
USART.Write ("Test program",13, 10, 10)
keypressed = 0
While 1 = 1
while keypressed = 0 'print key and exit when key pressed
Keypressed = keypad16.Value
If Keypressed <> 0 Then
USART.Write ("Key pressed = ", HexToStr(Keypressed), 13, 10)
End If
wend
while keypressed <> 0 'loop until key not pressed
Keypressed = keypad16.Value
wend
wend
The output of pressing each key in turn looks like this. It doesn't matter if a key is pressed and held down. It will be recorded only once.
Code:
Test program
Key pressed = 1
Key pressed = 2
Key pressed = 3
Key pressed = 4
Key pressed = 5
Key pressed = 6
Key pressed = 7
Key pressed = 8
Key pressed = 9
Key pressed = A
Key pressed = B
Key pressed = C
Key pressed = D
Key pressed = E
Key pressed = F
Key pressed = 10
Key pressed = 1
Key pressed = 2
Key pressed = 3
Key pressed = 4
Key pressed = 5
Key pressed = 6
Key pressed = 7
Key pressed = 8
Key pressed = 9
Key pressed = A
Key pressed = B
Key pressed = C
Key pressed = D
Key pressed = E
Key pressed = F
Key pressed = 10