*update!
By means of tedious code searching and studying im starting to see how to read the code and manipulate it.
Ive managed to get the code working with 8 extra pushbuttons:
/**
* MIDI Tjook
* 8 analog and 8 digital in to MIDI
*
* Using code from:
* midi_cc_test.pde
* @author Benjamin Eckel
*/
#define inputs 8
#define e 1 // this is the delta needed in
// currentPot[i] to send a message
int currentPot[8] = {0,0,0,0,0,0,0,0};
int pot[8] = {0,0,0,0,0,0,0,0};
int channel[8] = {1,2,3,4,5,6,7,8};
int switchPin1 = 38;
int switchPin2 = 40;
int switchPin3 = 42;
int switchPin4 = 44;
int switchPin5 = 46;
int switchPin6 = 48;
int switchPin7 = 50;
int switchPin8 = 52;
char note1 = 60; //Middle C
char note2 = 61; //D
char note3 = 62;
char note4 = 63;
char note5 = 64;
char note6 = 65;
char note7 = 66;
char note8 = 67;
int switchState1 = LOW;
int switchState2 = LOW;
int switchState3 = LOW;
int switchState4 = LOW;
int switchState5 = LOW;
int switchState6 = LOW;
int switchState7 = LOW;
int switchState8 = LOW;
int currentSwitchState1 = LOW;
int currentSwitchState2 = LOW;
int currentSwitchState3 = LOW;
int currentSwitchState4 = LOW;
int currentSwitchState5 = LOW;
int currentSwitchState6 = LOW;
int currentSwitchState7 = LOW;
int currentSwitchState8 = LOW;
void setup() {
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(switchPin5, INPUT);
pinMode(switchPin6, INPUT);
pinMode(switchPin7, INPUT);
pinMode(switchPin8, INPUT);
Serial.begin(31250); // baud rate = 31250 for midi
} // = 38400 for serial debug
void loop() {
for(int i=0; i<inputs; i++) {
currentPot[i] = analogRead(i) / 8;
if(abs(currentPot[i]-pot[i]) > e) {
sendMidi(channel[i], currentPot[i]);
pot[i] = currentPot[i];
}
}
{ //switchPin1
currentSwitchState1 = digitalRead(switchPin1);
if( currentSwitchState1 == HIGH && switchState1 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note1, 0x45);
if( currentSwitchState1 == LOW && switchState1 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note1, 0x00);
switchState1 = currentSwitchState1;
//switchPin2
currentSwitchState2 = digitalRead(switchPin2);
if( currentSwitchState2 == HIGH && switchState2 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note2, 0x45);
if( currentSwitchState2 == LOW && switchState2 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note2, 0x00);
switchState2 = currentSwitchState2;
//switchPin3
currentSwitchState3 = digitalRead(switchPin3);
if( currentSwitchState3 == HIGH && switchState3 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note3, 0x45);
if( currentSwitchState3 == LOW && switchState3 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note3, 0x00);
switchState3 = currentSwitchState3;
//switchPin4
currentSwitchState4 = digitalRead(switchPin4);
if( currentSwitchState4 == HIGH && switchState4 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note4, 0x45);
if( currentSwitchState4 == LOW && switchState4 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note4, 0x00);
switchState4 = currentSwitchState4;
//switchPin5
currentSwitchState5 = digitalRead(switchPin5);
if( currentSwitchState5 == HIGH && switchState5 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note5, 0x45);
if( currentSwitchState5 == LOW && switchState5 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note5, 0x00);
switchState5 = currentSwitchState5;
//switchPin6
currentSwitchState6 = digitalRead(switchPin6);
if( currentSwitchState6 == HIGH && switchState6 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note6, 0x45);
if( currentSwitchState6 == LOW && switchState6 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note6, 0x00);
switchState6 = currentSwitchState6;
//switchPin7
currentSwitchState7 = digitalRead(switchPin7);
if( currentSwitchState7 == HIGH && switchState7 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note7, 0x45);
if( currentSwitchState7 == LOW && switchState7 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note7, 0x00);
switchState7 = currentSwitchState7;
//switchPin8
currentSwitchState8 = digitalRead(switchPin8);
if( currentSwitchState8 == HIGH && switchState8 == LOW ) // push
//Note on channel 5 (0x94), some note value (note), middle velocity (0x45):
noteOn(0x94, note8, 0x45);
if( currentSwitchState8 == LOW && switchState8 == HIGH ) // release
//Note on channel 5 (0x94), some note value (note), silent velocity (0x00):
noteOn(0x94, note8, 0x00);
switchState8 = currentSwitchState8;
}
}
void noteOn(char cmd, char data1, char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}
void sendMidi(char chan, char val) {
Serial.print(0xB0, BYTE);
Serial.print(chan, BYTE);
Serial.print(val, BYTE);
}
As you can probably see, it's all just hacked together bits of code. I know it's not very efficient, but so far the latency has been very low and it works fine. Im trying to implement the part where it checks the pots in a similar way with the switches.
I also bought myself a rotary switch to do some experiments with. It's a 12 way 1 ground version from alpha. To extend the capabilities of the controller I would like to be able to change the midi channel(1 to 12) with the rotary switch so i can have 12 different lay outs with 8 pots and 8 buttons 8-).
Ive found this page where someone uses a rotary switch as a stepped potentiometer:
http://www.tasankokaiku.com/jarse/?tag=arduino
Can I use the presets in the code to change the midi channel number?