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
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(){
buttonsPressed = (digitalRead(buttonC) * 4) + (digitalRead(buttonB) * 2) + digitalRead(buttonA);
// 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: