ReneRichterDE / ButtonMatrix

The library allows easy interfacing with a keypad. Not only keypads connected directly to the IO pins of the microcontroller are supported, but also via I2C. Implements software debouncing
Other
1 stars 0 forks source link

Multiple MCP's? #5

Open ChristianKnorr opened 2 days ago

ChristianKnorr commented 2 days ago

Hi, how can I use multiple MCP's for a big Matrix? I have a Keyboard-Matrix with 7 Cols and 25 Rows.

Thank you

ReneRichterDE commented 2 days ago

Hi Christian,

well I have several news on this.

  1. Lets start with the bad one: Right now this isn't possible out of the box without any little programming.
  2. The good one is: I already have this on my list and should be released somewhere between two or three weeks

If you don't have the time to wait, you should be able to easily implement it by yourself by following these steps:

  1. Create your own implementation of the IO handler by inheriting the interface RSys::IOHandlerItf. There are just three methods to implement (you can use Adafruit_I2CIOHandler.h as a reference)
  2. In your own implementation create as many instances of the MCP as you need (or pass them in an array from the outside)
  3. Then delegate the calls to the different MCP instances, depending on the IO passed in the method parameters
  4. Finally pass and instance of your own IO handler class in the last parameter of the ButtonMatrix c'tor -> replace ADFI2C(mcp)

The idea I am following is: The change the number scheme of the IO pins in the button array to something like this:

Button buttons[ROWS][COLS] = {
    { (001), (002), (003) },
    { (004), (005), (006) },
    { (101), (102), (103) }
};

Notice the last row contains numbers starting from 100! This way you can easily determine the MCP instance by

int MCP_board_num = <pin number> / 100;
int MCP_pin_num = <pin_number> % 100;

With this algorithm up to ten boards could be supported in theory and it is also easily configurable without any complicated math.

Hope this helps!

Best regards RenΓ©

ChristianKnorr commented 2 days ago

Unfortunately it's too much for my skills, so I have to wait πŸ€·β€β™€οΈπŸ˜‰ Many thanks! πŸ‘Œ

ChristianKnorr commented 1 day ago

My Problem is solved. No, it's another, it's not a big matrix. So, my solution is to use 3 MCP's for 3 matrixes.

Tank you 😊