Relay and awitches for organ

Hello
Could anybody help me?
I''m building my home 3 manuals organ at home.
I have an arduino due, and a 16 relay board. I have 16 switches. I would like that when i press a switch the relay goes on and when i press the switch again the relay goes off, and i have 16 of awitches and relays.
I can't make the sketch with 16 switches and relays.
Could somebody help me?
Thank you so much
David

Can you post a schematic of your setup so that we know how the switches and relays are wired. Links to the relays (modules?) would help, too. Please read the "how to use the forum-please read" stickies to see how to format and post code and post the code that you have tried. It is not really hared to do what you want once we know what there is to work with.

Why not just connect the switches directly to the relays?

aarg:
Why not just connect the switches directly to the relays?

Then they'd need latching relays to get the desired latching effect.

davidjackson2017:
I would like that when i press a switch the relay goes on and when i press the switch again the relay goes off, and i have 16 of awitches and relays.
I can't make the sketch with 16 switches and relays.

To do what you want you will need 32 I/O pins. You could do it with an Arduino Mega without additional hardware or use something like shift registers to do it with an Arduino UNO. How are your electronics assembly skills?

Thank you so much for your replies!
Maybe i go more in details for what i would like to do. So I have in the computer an organ program called Hauptwerk connected with 3 midi organ keyboards. In this program I can connect any key of the computer keyboard ( 1, 2, 3, ...a, b, c...) with an i strumenti of the organ ( flute, bourdon, trumpet, oboe, etc) .ok.
I bought 16 Arcade bottons that i can connect to the pc, i want to assign to each botton an Instrument and i want that a led switch on when the instrument is on, and when i press again the button the instrument and the led go both off.

One possibility i thought was to use arduino due ( it has 54 digital pin i think) and a 16 relay board so that when i press 1 of the 16 Arcade botton i engage 1 instrument and because is connected to the relay i simultaneously switch on the led, and viceversa.
I power up the relay board separately, connect each relay to a digital pin of arduino, each botton connected to 5v and gnd and a digital pin of arduino. Do you think it could work? Could you help me with the sketch?
Thank so much
David

I can connect any key of the computer keyboard ( 1, 2, 3, ...a, b, c...) with an i strumenti of the organ ( flute, bourdon, trumpet, oboe, etc) .ok.

How do the relays simulate a computer keyboard keypress? To what are the relay switch sides connected? Will one and only one relay be closed at any one time?

botton connected to 5v and gnd

Only to ground. Use pinMode(pin, INPUT_PULLUP) to enable the internal pullup resistor.

The relays will need drivers. Look for relay modules with on board drivers.

Could you help me with the sketch?

It's what we are here for. Post your code and we will help.
A hint to get you started: Arrays and for loops.

const int KEYS = 16;

const byte keyPin[KEYS] = {
  // the key pins go here
 10,11,12,13,14,15,26,17,18,19,20,21,22,23,24,25
};

const byte relayPin[KEYS] = {
  // the relay pins go here
 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45
};

byte keyState[KEYS];
byte relayState[KEYS];
uint32_t debounce[KEYS];

void setup() {
  for(int i = 0; i<KEYS; i++) {
    pinMode(keyPin[i], INPUT_PULLUP);
    pinMode(relayPin[i], OUTPUT);
    keyState[i] = digtalRead(keyPin[i]);
    relayState[i] = LOW;
    debounce[i] = millis();
  }
}

void loop() {
  for(int i = 0; <KEYS; i++) {
    if(millis() - debounce[i] < 50) contiinue;
    byte prevKeyState = keyState[i];
    keyState[i] = digitalRead(keyPin[i]);
    if(prevState == HIGH && keyState[i] == LOW) {
      relayState[i] = relayState[i]==LOW ? HIGH : LOW;
      digitalWrite(relayPin[i], relayState[i]);
    }
  }
}

I don’t understand what the relays are going to do, but bear in mind that since you have a due you can use it to invoke keyboard presses on your PC so you may be able to select instruments that way.