Adafruit-MCP23017-Arduino-Library icon indicating copy to clipboard operation
Adafruit-MCP23017-Arduino-Library copied to clipboard

Bulk set gpio direction support

Open drakejest opened this issue 2 years ago • 1 comments

Hello would it be possible to add a function for bulk setting of INPUT/OUTPUT of the GPIO? im currently using 5 of these and 80 lines of code is used up for just setting the direction of the GPIO, i mean its not really a bad thing, just to make the code cleaner to look at. Alternatively having a function to read/write register directly would also be good as i can do the bulk setting of gpio direction there.

Thanks ! :)

drakejest avatar Apr 08 '23 14:04 drakejest

Hi. I'm also missing this feature, but I found a workaround. Fortunately, the pin argument in the function pinMode is an integer, and you can simply iterate over the whole port:

for (int8_t i = 0; i <= 15; i++) {
  mcp.pinMode(i, INPUT);
}

The same applies for the interrupt:

for (int8_t i = 0; i <= 15; i++) {
  mcp.setupInterruptPin(i, CHANGE);
}

jankokert avatar May 19 '23 08:05 jankokert