3 ms·
I wonder why they scan the keyboard as a set of columns and rows!! When I was at University, I created a 49 note midi controller from a discarded electric piano
by dools 13y ago
I wonder why they scan the keyboard as a set of columns and rows!! When I was at University, I created a 49 note midi controller from a discarded electric piano keyboard.
Basically I got the hardware and wrote software for a Motorola 68hc11 to control it. The way it worked was that you would put a value on an 8 bit register that would activate one "bit". This bit would be connected to 8 different keys on the keyboard. You would get an 8 bit value out the other end that would tell you which keys were connected at the time.
So for example the value:
01000000
might correspond go keys 1, 6, 11, 16, 21, 26, 31 and 36. If you got the value:
01011001
out the other end, you knew that keys 6, 16, 21 and 36 were pressed. The 68hc11 scanned so fast that you couldn't fool it. I remember my professor standing there for ages mashing the keyboard trying to get it to break with different key combinations.
If such an old microcontroller could handle 48 keys so easily, why the hell would a modern microcontroller not be able to use the exact same method? ie. instead of doing it in "rows and columns" just treat the keys as a linear array and deal with which keys are pressed and which aren't.
- dfox 13y agoYour scheme is essentially same as is used by keyboards and has the same problem. When you press two keys that are connected to same output wire, additional keys on these two inputs are ambiguous. There are some software tricks related to the fact that nobody presses multiple keys at exactly same time, but the root problem still exists.
- dools 13y agoBut there are no two keys connected to the same output wire at the same time. If I put the value: 00100000 onto the input register, and I get: 01000000 on the output register, that can only correspond to one key at the time I read the register. EDIT: I think perhaps you're underestimating how quickly a microcontroller can scan a keyboard. If I press 2 keys simultaneously that are both connected to the same output pin on the output register at different times, the rate at which I scan the input register is so fast that it would be physically impossible for me not to detect that as 2 distinct keys being pressed.
- dfox 13y agoThe problem happens when you press three or more keys at once in right combination. And is exactly the same regardless whether you scan output wires in sequence (as is done in simple hardware based keyboards of the 70's and 80's) or if you read them all at once. Going back to your original example, if one would press keys 1, 2 and 6 at the same time your microcontroller would falsely detect 7 as being also pressed (because keys 1 and 6 shorts two input wires together). This assuming that your output register drives strong 1 and weak (preferably floating) 0. If it has strong drive for both 0 and 1, then such combination of pressed keys would cause some unpredictable effect, possibly including burning out the pins.
- dools 13y agoHere's a dramatically simplified diagram to illustrate the principle: https://db.tt/Fvs0xBpd https://db.tt/Fvs0xBpd If I put a voltage on pin 2, and key A is pressed, I will get a voltage at pin 1. If I put a voltage on pin 3 and key B is pressed, I will get a voltage at pin 1. It doesn't matter if both are pressed simultaneously because I am reading them sequentially. All you have to do is scan the keys quickly enough that someone can't "sneak in" a key press in between scans which turns out is possible with even the lowest powered hardware.
- jfoks 13y agoGhosting is with three keys pressed: If there is a key A that is in the same row as a key B plus and also in the same column as a key C, then a fourth key (the 'ghost') appears to be pressed in the column of key B and the row of key C due to the shorting of the rows and columns, also in your scheme.
- dools 13y agoThere are no columns in this design. The behaviour you're describing can't occur since this isn't a 2d matrix of keys. The keys are grouped such that putting voltage on an input pin will result in an output voltage on many pins depending on which keys are pressed at the time.
- TheLoneWolfling 13y agoNo it isn't? He's basically running sets of 8 keys through a mux, and changing the selector of the mux to scan through the keys rapidly, 8 at a time. There is one output wire per key, at least until it gets to the mux.
- StavrosK 13y agoTo be fair, he didn't mention a mux anywhere. I read his comment four times and only figured it out when you replied.