For completeness, the Arduino sketch needs to be seen. Same as I posted elsewhere but with more comments.
//Arduino midi 13note bass pedals cobbled together by Jim Yale and inspired by...
//https://www.instructables.com/id/Build-MIDI-Bass-Pedals-for-About-150/
//Changed pin usuage to suit smaller Diecimila to Uno types. This is working on a Freeduino clone with ATmega168.
//Code rewrite to suit monophonic operation and additional features.
//MIDI shield not used only TX pin used for hardware MIDI output.
//Added midi channel select via dip switches only during startup. Selected by diode gating when pin13 is high.
//Added octave select rotary switch using 3bit diode coding to pins A0 to A2. Only values 0 to 4 used. Only available when pin13 is low.
//Added velocity pot on pin A3.
//Add tone generator for onboard synth using pin13 and Tone command. Settings cannot be checked while tone sounds.
struct key
{
int pin;
int midiKey;
int toneFreq;
};
// pin usage changed from original Mega board.
//Array used for key scan.
struct key keys[] =
{
{ 2, 24, 2093 }, // C Low. Values here used when key scan i = 0
{ 3, 25, 2217 }, // C#
{ 4, 26, 2349 }, // D
{ 5, 27, 2489 }, // D#
{ 6, 28, 2637 }, // E
{ 7, 29, 2794 }, // F
{ 8, 30, 2960 }, // F#
{ 9, 31, 3136 }, // G
{ 10, 32, 3322 }, // G#
{ 11, 33, 3520 }, // A
{ 12, 34, 3729 }, // A#
{ A5, 35, 3951 }, // B
{ A4, 36, 4186 }, // C High. Values here used when key scan i = 12
{ 0, 0, 0,} // End of array. Key scan ends when pin value of 0 found.
};
int keyOffset = 12; //octave setting
int keyVelocity = 127; //max velocity
int MidiChannel = 0; // just a default value
int NoteOnCd = 0x90; // the midi note on command code is the "9", the "0" will be replaced by the midi channel number.
int NoteOffCd = 0x80; // as above, the "8" is the note off command & the "0" is the channel.
int PotVal = 100; // just a default velocity value to start with
int PotPin = 3; // the analog read pin for velocity.
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); //Set pin13 to read midi channel data
// Enable pedal key inputs
for (int i = 0; keys[i].pin != 0; ++i)
{
pinMode(keys[i].pin, INPUT_PULLUP);
}
//Use A0 to A4 to read 4 bit midi channel switches
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
if (digitalRead(A0) == HIGH) {
MidiChannel += 1;
}
if (digitalRead(A1) == HIGH) {
MidiChannel += 2;
}
if (digitalRead(A2) == HIGH) {
MidiChannel += 4;
}
if (digitalRead(A3) == HIGH) {
MidiChannel += 8;
}
//Construct midi note on & off messages for selected channel by "or"ing with the midi command.
NoteOnCd |= MidiChannel;
NoteOffCd |= MidiChannel;
delay(500); // will light the Activity LED briefly for confidence.
digitalWrite(13, LOW); //Deselect channel switches.
//start serial with midi baudrate 31250
Serial.begin(31250);
octave(); //initialise selected octave
Velocity(); //Initialise velocity pot value
//End of setup, functions follow.
//
}
void Midi_Send(byte cmd, byte data1, byte data2)
{
Serial.write(cmd);
Serial.write(data1);
Serial.write(data2);
}
void noteOn(int midiKey)
{
Midi_Send(NoteOnCd, midiKey, keyVelocity);
}
void noteOff(int midiKey)
{
Midi_Send(NoteOffCd, midiKey, keyVelocity);
}
void octave()
{
keyOffset = 0;
digitalWrite(13, LOW);
if (digitalRead(A0) == HIGH) {
keyOffset += 1;
}
if (digitalRead(A1) == HIGH) {
keyOffset += 2;
}
if (digitalRead(A2) == HIGH) {
keyOffset += 4;
}
keyOffset *= 12;
}
void Velocity() {
digitalWrite(13, LOW);
PotVal = analogRead(PotPin) / 8; //convert 10bit ADC result to 7bit range for midi.
keyVelocity = (keyVelocity + PotVal) / 2; //average with the previous reading to smooth result.
}
//End of functions, main loop follows
//
void loop() {
// Main Loop
byte byte1;
byte byte2;
byte byte3;
int value;
//
// Scan pedal keys
for (int i = 0; keys[i].pin != 0; ++i)
{
value = digitalRead(keys[i].pin);
if (value == LOW) // Key pointed to by i is on
{
noteOn(keys[i].midiKey + keyOffset); // Send the MIDI note on message
tone(13, keys[i].toneFreq); //Play tone for synth
delay(20); //Wait out any contact bouncing before looking for note off
do //Look for note off
{
value = digitalRead(keys[i].pin);
}
while (value == LOW); //Note off contact is defined by pull-up - it cannot bounce down hence no debounce.
noteOff(keys[i].midiKey + keyOffset); //Send MIDI note off
noTone(13); //End synth tone
}
}
octave(); //Update octave setting
Velocity(); //Update velocity value
}