Skip to content

Instantly share code, notes, and snippets.

@dnnyg33
Last active February 18, 2021 11:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnyg33/74e646c33546ba814ea79fda73d3cacd to your computer and use it in GitHub Desktop.
Save dnnyg33/74e646c33546ba814ea79fda73d3cacd to your computer and use it in GitHub Desktop.
Midi Organ pedalboard arduino sketch
boolean C1 = 1;
boolean CS1 = 1;
boolean D1 = 1;
boolean DS1 = 1;
boolean E1 = 1;
boolean F1 = 1;
boolean FS1 = 1;
boolean G1 = 1;
boolean GS1 = 1;
boolean An1 = 1;//has a lowercase n (stands for note), because it wouldn't compile as A0.
boolean AnS1 = 1;
boolean Bn1 = 1;
boolean C2 = 1;
boolean CS2 = 1;
boolean D2 = 1;
boolean DS2 = 1;
boolean E2 = 1;
boolean F2 = 1;
boolean FS2 = 1;
boolean G2 = 1;
boolean GS2 = 1;
boolean An2 = 1;
boolean AnS2 = 1;
boolean Bn2 = 1;
boolean C3 = 1;
boolean C1last = 1;
boolean CS1last = 1;
boolean D1last = 1;
boolean DS1last = 1;
boolean E1last = 1;
boolean F1last = 1;
boolean FS1last = 1;
boolean G1last = 1;
boolean GS1last = 1;
boolean A1last = 1;
boolean AS1last = 1;
boolean B1last = 1;
boolean C2last = 1;
boolean CS2last = 1;
boolean D2last = 1;
boolean DS2last = 1;
boolean E2last = 1;
boolean F2last = 1;
boolean FS2last = 1;
boolean G2last = 1;
boolean GS2last = 1;
boolean A2last = 1;
boolean AS2last = 1;
boolean B2last = 1;
boolean C3last = 1;
boolean last[] = {C1last, CS1last, D1last, DS1last, E1last, F1last, FS1last, G1last, GS1last, A1last, AS1last, B1last, C2last, CS2last, D2last, DS2last, E2last, F2last, FS2last, G2last, GS2last, A2last, AS2last, B2last, C3last};
int lowestNote = 36;//The lowest C pedal on an organ (or at least mine) is 36 aka C1
int numberOfPedals = 25;
int vol = 0;
void setup() {
Serial.begin(31250);
pinMode(22, INPUT_PULLUP);
pinMode(23, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
pinMode(33, INPUT_PULLUP);
pinMode(34, INPUT_PULLUP);
pinMode(35, INPUT_PULLUP);
pinMode(36, INPUT_PULLUP);
pinMode(37, INPUT_PULLUP);
pinMode(38, INPUT_PULLUP);
pinMode(39, INPUT_PULLUP);
pinMode(40, INPUT_PULLUP);
pinMode(41, INPUT_PULLUP);
pinMode(42, INPUT_PULLUP);
pinMode(43, INPUT_PULLUP);
pinMode(44, INPUT_PULLUP);
pinMode(45, INPUT_PULLUP);
pinMode(46, INPUT_PULLUP);
pinMode(52, OUTPUT);
// midiProg(0xC0, 1);//still deciding how to trigger this while the code is looping. 0xC0 is midi for program change and second param is which setting.
}
void loop() {
vol = 1023;//analogRead(A5);//1023 is max volume. This can be replaced with a potentiometer later, but for now i'll just use the volume knob on my amp
vol = map(vol, 0, 1023, 0, 127);
C1 = digitalRead(41);//41
CS1 = digitalRead(43);//43
D1 = digitalRead(30);//30
DS1 = digitalRead(32);//32
E1 = digitalRead(36);//36
F1 = digitalRead(22);//22
FS1 = digitalRead(45);//45
G1 = digitalRead(38);//38
GS1 = digitalRead(27);//27
An1 = digitalRead(37);//37
AnS1 = digitalRead(39);//39
Bn1 = digitalRead(23);//23
C2 = digitalRead(29);//31
CS2 = digitalRead(24);//28
D2 = digitalRead(44);//44
DS2 = digitalRead(46);//24
E2 = digitalRead(26);//26
F2 = digitalRead(31);//42
FS2 = digitalRead(28);//29
G2 = digitalRead(40);
GS2 = digitalRead(42);//40
An2 = digitalRead(25);//25
AnS2 = digitalRead(35);//35
Bn2 = digitalRead(34);//34
C3 = digitalRead(33);//33
boolean inputs[] = {C1, CS1, D1, DS1, E1, F1, FS1, G1, GS1, An1, AnS1, Bn1, C2, CS2, D2, DS2, E2, F2, FS2, G2, GS2, An2, AnS2, Bn2, C3};
for (int index=0; index<numberOfPedals; index++) {
if (inputs[index] != last[index]) {
if (inputs[index] == 0) {
noteOn(0x90, lowestNote+index, vol);
}
else {
noteOn(0x80, lowestNote+index, 0x00);
}
}
last[index] = inputs[index];
}
delay(50);
}
void noteOn(byte cmd, byte data1, byte data2) {
if (data2 == 0x00) {//triggers an led to light up whenver a note is produced.
digitalWrite(52, LOW);
} else {
digitalWrite(52, HIGH);
}
Serial.write(cmd);
Serial.write(data1);
Serial.write(data2);
delay(10);
}
// Send a two byte midi message
void midiProg(char status, int data ) {
Serial.write(status);
Serial.write(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment