Hello,
Iv'e got this problem where I'm supposed to send midi data from a function to the main loop, so I can show it on an OLED display. I can't figure it out. I understand the principles, but can't handle the code right it seem.
I need the usbMIDI.sendControlChange(pin,val,channelNumber) values in the bottom.
Some say that the struct definition should be put in an extra .h file to get it right, is it the way maybe? I cant make it work where ever I put the definition. I only get "not defined in this scope".
I've got the explanation to do something like this:
struct Event {
int data;
int time;
};
Event GetEvent() {
Event e;
e.data = 127;
e.time = 123456789;
return e;
}
The code, not showing the whole void loop, just the part I need help with. I want the data into the display.println rows.
//DISPLAY____________________________________
//Display text
display.setCursor(0,0);
display.print("CC number ~ "); // Change to CC number?
display.println(); //Put CCnumber here
display.setCursor(0,12);
display.print("says hi at");
display.setCursor(0,24);
display.print("MIDI channel ~ ");
display.println(); // Put midichannel here
display.setCursor(0,36);
display.print("n tickling");
display.setCursor(0,48);
display.print("VALUE number ~");
display.setCursor(91,48);
display.println(); // to vary 0 to end result, ie 1024/? //Put CC value here
//Display progress bar
display.fillRect(0, 63, valDisplay, 1, 1); // 2=V from left; 61=H from top; val/8= lenght of bar ie,
//val/16 is half screen with full value; 3= thickness of slide bar; 1= ? colour or brightness
display.display();
display.clearDisplay(); // Clear display must be used to clear text etc
} // LOOP END
// ...
// COMMUNICATION FUNCTIONS ________________________________________________________________________________
// http://www.pjrc.com/teensy/td_midi.html
//debug out
void serialDebugOut(String cType, int cNum, String cVal){
Serial.print(cType);
Serial.print(" ");
Serial.print(cNum);
Serial.print(": ");
Serial.println(cVal);
}
//function to send MIDI
void midiSend(char type, int val, int pin){
String clickState;
switch (type){
case 'p': //--------------- PUSHBUTTON
if(enableDebug){
if(val==1){
clickState = "click on";
}else{
clickState = "click off";
}
serialDebugOut("Pushbutton",pin,clickState);
}
else{
if(val==1){
//usbMIDI.sendNoteOn(pin,127,channelNumber); //!!!
}else{
//usbMIDI.sendNoteOff(pin,127,channelNumber); //!!!
}
}
break;
case 'e': //--------------- ENCODER
if(enableDebug){
if(val==1){
clickState = "forward";
}else{
clickState = "reverse";
}
serialDebugOut("Encoder",pin,clickState);
}
else{
if(val==1){
//fuzzy
//usbMIDI.sendNoteOn(pin+26,127,channelNumber); //!!! //we have 26 used digitals, thus must add 26
//ableton
//usbMIDI.sendControlChange(pin+23,68,channelNumber); //!!! //we have 23 used analogs, thus must add 23
//other
//usbMIDI.sendControlChange(pin+23,65,channelNumber); //!!! //we have 23 used analogs, thus must add 23
}
else{
//fuzzy
//usbMIDI.sendNoteOff(pin+26,127,channelNumber); //!!! //we have 26 used digitals, thus must add 26
//ableton
//usbMIDI.sendControlChange(pin+23,60,channelNumber); //!!! //we have 23 used analogs, thus must add 23
//other
//usbMIDI.sendControlChange(pin+23,63,channelNumber); //!!! //we have 23 used analogs, thus must add 23
}
}
break;
case 'a': //--------------- ANALOG
if(enableDebug){
if(pin>15){
serialDebugOut("Analog Teensy",pin,val);
}else{
serialDebugOut("Analog mux",pin,val);
}
}else{
usbMIDI.sendControlChange(pin,val,channelNumber); //!!!
}
break;
}
}
Thanks for your support!