HI
( searched the forum and google it ) need help with midi banks
I have the basic code working as I like and like to add 3 buttons to change midi notes ( 3 midi banks of 8 notes each bank )
any help is very welcome
( searched the forum and google it ) need help with midi banks
I have the basic code working as I like and like to add 3 buttons to change midi notes ( 3 midi banks of 8 notes each bank )
any help is very welcome
Code:
/*digital read base from
* https://raw.githubusercontent.com/langsound/Digital-Electronics/master/Teensy_MIDI_code_lesson/ManyButtonsManyNotes_Functions_D_NC/ManyButtonsManyNotes_Functions_D_NC.ino
*/
int myLED = 13;;
int myButtons[8];//16
int myOldButtons[8];//16
int myNotes[8] = {60, 62, 64, 65, 67, 69, 71, 72} ;//16
int myVelocity = 127;
int myChannel= 2;
/*****analog area****/
/* base from http://djtechtools.com/2015/08/25/how-to-make-your-own-diy-midi-controller/
* */
// define how many pots are active up to number of available analog inputs
#define analogInputs 2
// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// make array of cc values
int ccValue[analogInputs];
// index variable for loop
int a;
/////
/*******void analog******/
void readanalog(){
// loop trough active inputs for knobs
for (a=0;a<analogInputs;a++)
{
// read current value at i-th input inputAnalog[i] = analogRead(i);
// if magnitude of difference is 8 or more… if (abs(inputAnalog[i] – iAlag[i]) > 7){
// calc the CC value based on the raw value
ccValue[a] = inputAnalog[a]/8;
// send the MIDI
usbMIDI.sendControlChange(a, ccValue[a], 3);
// set raw reading to lagged array for next comparison
iAlag[a] = inputAnalog[a];
}
delay(10); // limits MIDI messages to reasonable number
}
/*******end void analog******/////
void readMyButtons(){
for(int i; i<8; i++){
myButtons[i] = digitalRead(i);
}
}
void playMyNotes(){
for(int i; i<8; i++){
if(myButtons[i] != myOldButtons[i]){
myOldButtons[i] = myButtons[i];
if(myButtons[i]){
usbMIDI.sendNoteOn(myNotes[i], myVelocity, myChannel);
digitalWrite(myLED, HIGH);
delay(5); //// try 1
}
else{
usbMIDI.sendNoteOn(myNotes[i], 0, myChannel);
digitalWrite(myLED, LOW);
}
}
}
}
void setup(){
pinMode(myLED, OUTPUT);
for(int i; i<8; i++){
pinMode(i, INPUT);
}
}
/*
* void Looopppppppppppppplooop
*/
void loop(){
readMyButtons();
playMyNotes();
readanalog();
// MIDI Controllers should discard incoming MIDI messages.
while (usbMIDI.read()) {
// ignore incoming messages
}
}
Last edited: