Hello
Yes you have.
Drop all information related to the relays into an object using the struct instruction and design a method or service to handle these data.
Have a nice day and enjoy coding in C++.
in C and C++ function parameters are passed by value - any changes made to parameters inside the function (such as relayState) are not passed back to calling program
you should use pass by reference which enables changes made to parameter values within the function to be passed back to the calling program
e.g. try passing relayState by reference
void relayChange(bool &relayState, const int relay, String relayName)
I notice that the code executed for "if (relayState == 0) {" is identical to the code executed for "if (relayState == 1) {" so you can get rid of the 'if' statements:
Note: Shouldn't you change the state BEFORE you write the new state to the pin?
I changed it and it worked.
As to putting one feather in my cap I will do that but I was kinda forced into rewriting my code as the memory in my Arduino Mega was over 91% full and I had warning about issues with memory