Hi, I am trying to build an electronic go board. I built a prototype that uses keypad matrix of switches to detect when any of the switches is closed. I am using, in total, 18 pins for a 9 by 9 matrix. My goal is to expand the circuitry to handle 19 by 19 switches so that'll require 38 pins in total.
On top of that, I want to be able to send signals from a PC to any location on the board. So like potentially one LED at each location on the board, which can be individually controlled by a program. I read that a shift register can control multiple LEDs at once, which got me to think that maybe I can use a shift register to monitor the 361 switches? If that is the case I might not need to construct the matrix after all?
I'm not sure if this is possible. Can someone give me some comments about this idea?
p.s. I read that a shift register with 4 pins can control 16 individual LEDs. Does that mean I need to find a shift register to control 361 LEDs?
If you're checking switches that can be operated in any combination, then you have to put a diode in series with each one. The good news is that for a board game, the scanning can be very slow and still function properly. For the LEDs you would have to think about the duty cycle of any given LED, where if they were wired as a 19x19 matrix, each one could only be on for 1/19 of the time. That means that the current would need to be pretty high in order to give you anything but a very dim output, and the LEDs might not be able to stand that kind of operation, with high current flowing for brief intervals.
With 361 switches, the matrix would still be needed, unless you wanted to use a lot of shift registers. The common shift registers used with an arduino are eight bits (74HC595 / 74HC165), you would need three of each for a matrix keyboards (total of five if you rearrange the matrix to 24x16) , or forty-six for separate inputs for each key.
Probably easiest to use addressable LEDs instead of trying to multiplex those. Multiplexing would add complexity to the code, and a lot of external hardware, shift registers and transistors.
That sounds odd, more like a 4 to 16 decoder chip, don't see many of those. Shift registers generally need connections for power, ground, data, clock, and latch, but multiple shift registers can be chained together for as many outputs as are needed. The practical limit is the drive capacity of the arduino output pins for the data/clock/latch.
Are you saying that the shift registers interface with the 38 row / column wires of the 19 by 19 matrix rather than the 361 switches themselves directly? I guess I can lay the addressable LEDs to match the 19 by 19 locations on the board.
The 19x19 matrix requires less hardware. 361 switches directly connected to shift registers would need 46 shift registers (with 8 switches per shift register).
Looking at the addressable LEDs I found on the internet, they don't look so customizable in terms of their spacing. Is there any such LED strips that I can bend or modify the spacing between individual LEDs??
You can buy the addressable LEDs individually, or search for addressable LED strings instead of strips, those have a few inches of wire between the LEDs.
Oh! I didn't expect you to use only one pin for all of them. Did you need to tweak something or this is just how addressable LEDs are capable of doing?
Might be worth keeping in mind that Whilst Neopixels are great and come cheap, they put a lot of pressure on the interrupt system which can interfere with other software needs like the refresh rate of the switches scanning or handling Serial. Of course a faster MCU can help there too.
I tend to prefer APA102 types that don’t have the same constraint when I want to keep cycles readily available
I think "put a lot of pressure on the interrupt system" are the wrong words to use.
True rapid refresh can interfere with things like the servo library and serial reception, because during the refresh time all the interrupts are turned off.
If this becomes an issue then remember you only have to refresh the WS2812 buffers when you want to change them. If you are happy with the way the lights are at the moment then there is no need to refresh them, they are set and forget. Also there are hardware alternatives to driving servo motors.
The case often arises when you are making a continuously changing light show on the LEDs. But you just want them to reflect the state of the switches, you only need to refresh them when the switches change.
Unless of course you use something like the Pico 2040 processor that has built in hardware state machines that can refresh a string of WS2812 LEDs without any CPU involvement.
Yes I often use these as well, but these are not available in as may different physical form factors as the WS2812 types.