// POT Variables:
int input_nb = 6; // number of analog inputs
int AV[6] = {0,0,0,0,0,0}; // define variables for the controller data
byte LastAV[6] = {0,0,0,0,0,0}; // define the last value variables
byte midiCCselect[6] = {20,21,22,23,24,25}; // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[6] = {1,1,1,1,1,1}; // select threshold for each analog input
// BUTTON Variables:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
byte note = 0;
void setup() {
// Set MIDI baud rate:
Serial.begin(31250); // 31250
//**BUTTONS**
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
//**POTS**
for (int x =0; x < input_nb; x++) { // initialisation; condition; increment
// Pot value = 1023
AV[x] = analogRead(x);
// Divide this value so it equals 127 (for MIDI)
int cc = AV[x]/8;
// If the Control Change is not equal to the last analog value, then send a MIDI CC:
if (cc !=LastAV[x]) {
//MIDI Control Change
midiCC(0xB0, midiCCselect[x], cc);
// The last value read becomes the new value for the next if statement:
LastAV[x] = cc;
}
// **BUTTONS**
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is LOW:
if (buttonState == HIGH) {
// Play a MIDI note:
noteOn(0x90, note, 0x40);
}
else {
// Note OFF??:
digitalWrite(ledPin, LOW);
}
}
}
// **POTS** sends a Midi CC.
void midiCC(byte CC_data, byte c_num, byte c_val){
Serial.write((byte)CC_data);
Serial.write((byte)c_num);
Serial.write((byte)c_val);
}
// *BUTTONS**
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
This is my code so far (it is a bit of a mess, I apologise!)