I am working on a project with an ESP32 and a MCP23017.
In the main program I create an object for the MCP and initialize the address.
Adafruit_MCP23X17 pin_Expander;
const int expander_addr = 0x20; // Adress 0x20
void setup()
{
Serial.begin(9600);
pin_Expander.begin_I2C(expander_addr);
expander_Init(pin_Expander);
}
Since I use many IOs in the project, I wanted to outsource the initialization of these and wrote a function. I have created a separate header file for the function.
void expander_Init(Adafruit_MCP23X17 pin_Expander)
{
// Load the GPIOs
pin_Expander.pinMode(pin1_Motor1, OUTPUT); // I have removed the other pins
// Set all GPIOs to LOW
pin_Expander.digitalWrite(pin1_Motor1, LOW); // I have removed the other pins
}
I wonder if this is a legitimate way to pass an object into another function?