: : Arrange the button connections as an 8 by 8 matrix (8 rows, 8 columns).
:No can do. i've investigated a martix and the only problem is that you can not tell which buttons are being pressed if more than one button is pressed. i need to be able to tell exactly which buttons are on and off all of the time.
You are thinking of a diode matrix to give a unique 8-bit number to each key. Yes, such a system is unable to detect n-key rollovers (multiple buttons pressed) correctly.
But, with the system I described, using the buttons themselves in a scan matrix, you WILL be able detect all of the buttons that are pressed! In each iteration of the outer loop of the software, one row of 8 buttons is enabled, with the other 7 rows (56 buttons) disabled. The iteration of the inner loop then checks each of the 8 column buttons in the enabled row, detecting each one that is pressed. The outer loop then disables the first row (and all the other rows) and enables the second row. Again the inner loop checks each of the columns in that row. The process continues, checking each of the 64 buttons. If more than one button is pressed: let's say three buttons are pressed, it will detect each of the three buttons.
:If you know of a wany to compress the information contained in 64 bits so that you could easily extract it (or not so easily) that would be great!
In effect, that is what the hardware system does! The 64 bits of information is time-multiplexed, dividing the available time into slices of eight and using each slice to send 8 bits of information. The software then latches the information coming through on the slices to put it back together as 64 bits of data.
To perhaps make this more clear, here is the pseudo-code rewritten to specifically show the state of each (and every) button:
(numbers are decimal, AND is the logical bitwise operator AND)
let rownum = 1
let writebitnum = 1
do while writebitnum is less than or eqal to 8
Output rownum to the serial port
let colnum = 1
let readbitnum = 1
let inp = serial input
do while readbitnum is less than or equal to 8
display on the console:
"button at row" writebitnum "and column" readbitnum "is"
if inp AND colnum is true (1) then display on the console:
else if inp AND colnum is false (0) then display on the console:
display a carraige return and linefeed on the console
let colnum = colnum x 2
let readbitnum = readbitnum + 1
let rownum = rownum x 2
let writebitnum = writebitnum + 1
Now, when this code is invoked, 64 lines will be displayed on the computer console describing where each of the 64 buttons is in the matrix, and stating whether or not it is pressed.
Perhaps eliminating the logarithm base 2 stuff will help relieve some confusion (actually, it is still there -- it's just that the routine generates the logarithms).
BTW, I just realized that the hardware system as described won't work because of TTL specs. It may work with mos type uarts but probably not. When the buttons are open (not pressed), it leaves the uart inputs floating, and they will probably float high. So the computer will always see a 255 (11111111 binary) on the serial input. Pulling each of the 8 usart inputs low with a 4.7k ohm resistor will probably fix it for mos uarts. For TTL uarts, you would probably have to pull the inputs high with 1k ohm resistors, then change the software to invert the port putputs and inputs. That is, a 1 on coming in would indicate a non-pressed button, and a 0 would indicate a pressed one.
Hope this helps