Newbie here..
The kind Grumpy_Mike made me a simple but effective sketch sending MIDI programchange to a PC using an arduino pro micro. I modified it slightly according to my needs and it worked beyond my wildest dreams! ( Been using a simple but working sketch before that but it was buggy).
Now I'm trying to modify it further by making it send controlChange instead but I always get this error (see attached image. It seems i dont have an idea of the controlChange parameter needed.
In this part of the code, it seem simple enough for programChane but simple substitution didn't work for the controlChange part (I have no prior programming training; just sort of curiosity and eagerness to learn new things type of education
)
void programChange(byte channel, byte patch) {
midiEventPacket_t event = {0x0C, 0xC0 | channel, patch};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
Thank you so much for any help.
here is the full code
// Simple MIDI output of program message through USB
// By Grumpy_Mike August 2019
#include <MIDIUSB.h>
// to add more then simply add more pins tothe list
byte ledPin[] = {A0,A1,A2,A3,A6,A7,A8,A9,A10}; // list of led pins
byte buttonPin[] = {0,1,2,3,5,7,15,14,16}; // list of buttons pins
byte buttonState[] = {0,0,0,0,0,0,0,0,0}; // start off with off
byte lastButtonState[] = {0,0,0,0,0,0,0,0,0}; // start off with off
//byte programChanges[] = {0,1,2,3,4,5,6,7,8}; // list of program change messages to send
byte controlChanges[] = {66,67,68,69,70,71,72,73,74};
byte channel = 0; // for musicians this is channel 1
// Variables will change:
//int buttonPushCounter = 0; // counter for the number of button presses
int up_buttonState = 0; // current state of the up button
int up_lastButtonState = 0; // previous state of the up button
int down_buttonState = 0; // current state of the down button
int down_lastButtonState = 0; // previous state of the down button
//bool bPress = false;
void setup() {
for(int i =0;i< sizeof(buttonPin); i++){ // initialise input pins
pinMode(buttonPin[i], INPUT_PULLUP); // wire all buttons between input and ground
pinMode(ledPin[i], OUTPUT);
//}
//{
//Serial.begin(9600);
// pinMode( Up_buttonPin , INPUT_PULLUP);
// pinMode( Down_buttonPin , INPUT_PULLUP);
}
}
void loop() {
for(int i =0;i< sizeof(buttonPin); i++){ // look at all pins
buttonState[i] = digitalRead(buttonPin[i]);
if(buttonState[i] == LOW && lastButtonState[i] == HIGH) { // remember how you wired your buttons LOW = pressed
ledOffAll();
digitalWrite(ledPin[i],HIGH);
controlChange(channel, control, value, controlChanges[i]); // send the program change message
MidiUSB.flush();
}
lastButtonState[i] = buttonState[i];
}
}
void ledOffAll() {
for(int i = 0 ; i< sizeof(ledPin); i++){
digitalWrite(ledPin[i], LOW);
}
}
void programChange(byte channel, byte patch) {
midiEventPacket_t event = {0x0C, 0xC0 | channel, patch};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
{
}
}
