|
Simple reed switch matrix scan simulator for a 3x3 matrix board, such as a magnetic Tic-Tac-Toe game board. The LEDs are both visual indicators of the selected cells, and diodes to prevent "ghosting". Columns are set to INPUT_PULLUP, so the corresponding pins read HIGH, as indicated by 3 top logic source buttons. Rows are initially OUTPUT HIGH, but are pulled LOW during the scan, one by one. This is accomplished by the 3 side logic train buttons, set to 33% pulse width, with 0%, 33.3% and 66.7% delay, top to bottom.
On an Arduino, this can be done with a nested for-loop, presuming a rows[] and columns[] arrays are configured with corresponding pins, and the pins are properly initialized:
for (int row = 0; row < 3; row++)
{
// Pull the row LOW to test it
digitalWrite(rows[row], LOW);
// Scan each column at this row
for(int col = 0; col < 3; col++)
{
// LOW pins are ON at [row, col]
bool isOn = digitalRead(columns[col]) == LOW;
}
// Pull the row HIGH to test the next row
digitalWrite(rows[row], HIGH);
}
To simulate a magnet placed on the board, close the SPST switch next to the corresponding LED. To remove the magnet, open the switch.
|