# Combination of many switches with different results

Hello,

i'm new here. Can you help me please. I think it isn't so difficult, but I don't know the answer now.
If I would create a MIDI Piano (I don't do it) I would have many switches and every switch would have one sound.
My Problem is, that I have to create an instrument that can play sounds with combinations of switches. Like a trumpet. You have three valves but with combination of these three valves. So you can have 8 different combinations to press the three valves.

One example:
Switch 1 = LED A
Switch 2 = LED B
Switch 1 and Switch 2 together = LED C

Has anyone an idea how to say that to my Arduino?

Thank you so much!

Read and save the values from all the switches. Then use some suitable IF statements to decide what to do.

The Arduino is very fast. The time taken to do all that would not be noticed by a human.

...R

Just a little thought...
A, B or C isn't always A+B = C

A+B may form beats/harmonics or other known artefacts. It all depends on the frequencies of A & B (among other things)

Umm.. So A & B are not binary values but perhaps functions of time? Like frequencies? Or inputs to a synth filter?

-jim lee

``````byte buttonA = 2; // pin assignments
byte buttonB = 3;
byte buttonC = 4;

byte outputNote = 6;

byte buttonsPressed;

void setup(){
pinMode (buttonA, INPUT_PULLUP);
pinMode (buttonB, INPUT_PULLUP);
pinMode (buttonC, INPUT_PULLUP);

pinMode (outputNote, OUTPUT);
}

void loop(){
// result is a unique number from 0 to 7

switch (buttonsPressed){
case 0:
// play note for no buttons, or maybe no buttons = no note
break;
case 1:
// play note for A
break;
case 2:
// B
break;
case 3:
// B & A
break;
case 4:
// C
break;
case 5:
// C & A
break;
case 6;
// C & B
break;
case 7:
// C & B & A
break;
} // end switch
} //end loop
``````

I'd add a fourth button, only play one of the 8 notes (0 to 7) when the 4th button was pressed, be like playing a note only when wind was blowing thru the trumpet. So only go into the switch:cases when the 4th button was pressed.

See my "piano tones from micros()" sketch here for a way to create the notes & be very responsive to buttons being pressed: