How to switch continuity direction on a grid?
Actually, you'll note that there are four distinct sets of squares in your grid:


Some of the squares are always at +5V
Some of the squares are always at Gnd
Some of the squares are at +5V for the "horizontal" grid, and Gnd for "vertical"
The rest of the squares are the opposite of the previous set.


Therefore, you need four signals: +5V, Gnd, and two out-of-phase square waves; wire each square to the appropriate signal and you're done!

EDIT

Since the above answer was written, comments associated with the question indicate that it's really a position detection problem, not simply a question of driving a voltage pattern on the grid of squares. This will require a completely different approach.







simulate this circuit &ndash; Schematic created using CircuitLab

In the diagram above, the dashed boxes represent the sensing squares. Note that within each 2&times;2 group, the pattern of diodes on each square is unique. The pattern can be repeated indefinitely to make a larger grid.

To use, drive each "col drive" line high, one at a time, and look at which "col sense" lines show signal. Then, drive each "row drive" line high, one at a time, and see which "row sense" lines show signal. Make sure you hold all the row drive lines low while scanning the columns, and vice-versa.

If position information is not required, then all of the row drive lines can be connected together, and all of the col drive lines can be connected together. Similarly, the row sense lines can be tied together (using a single sense resistor) and the col sense lines can be tied to another sense resistor.