Change variables in a function with parameters?

hi all,

I have a lot of button that need checking and do a Keyboard.write();
I want do write a function or a for-loop to do this for all the buttons.

my idea was:

void loop()
{
CheckSwitch( 7, “state7”, “lastState7”, 65);
}
void CheckSwitch (int pin, String state, String lastState, int key)
{
state = digitalRead(pin);
if (state != lastState)
{
if (state == LOW)
{
Keyboard.write(key);

}
delay(50);
}
lastState = state;
}

it copiles, but give no output.
is it even possible to change variables inside a function like this?
could you recommend another way to do this?

Thank You :slight_smile:

Have you checked the return type of digitialRead? it's HIGH or LOW and these are constants, check this link

void CheckSwitch (int pin, String state, String lastState, int key)
{

It makes no sense to try to store the value read from a pin in a String. It makes no sense to try to compare that String to LOW.