-
|
Hello, I'm Louta. I'm new user of arduino midi library. I'm french and i don't know if i can speak french here so I try in English. So please apologize me for my bad english, i do my best without translator. If you don't understand me let me know it. I try to make a midi interface with arduino due to control a audio VCA with DAC of arduino due. For that i use DAW with NRPN fonction to control software volume. the output of Midi enter in my midi arduino interface. I try to get CC6(MSB) and CC38(LSB) value for have 4096 resolutions of my DAC. I send you my code, can you help me please? I need help for receive the information of CC6 and CC38 and send it to the int associed because it don't work. Thank you for your help. #include <MIDI.h>
int CC6Fader1Read = 0;
int CC38Fader1Read = 0;
int FaderValue1 = (CC38Fader1Read+1)+(128*CC6Fader1Read);
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
MIDI.begin(1); // Initialize the Midi Library.
MIDI.setHandleControlChange(MyCCFunction);
}
void loop() {
MIDI.read();
analogWriteResolution(12);
analogWrite(DAC0, FaderValue1);
}
void MyCCFunction(byte channel, byte number, byte value) {
switch (number) {
case 6:
CC6Fader1Read = value;
break;
case 38:
CC38Fader1Read = value;
break;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
|
Your issue is that the computed value If you update the calculation after storing each CC, your loop should pick it up at the next tick and write the correct output. En Français : Le souci vient du fait que ta variable |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your help, I change that. Now if i change value of CC6Fader1Read it change but a think the value of them are not updating. Mabe I have a problem with my Midi connection? For you the code to receive Midi CC and store value in int CC's is ok? #include <MIDI.h> // Add Midi Library
int CC6Fader1Read = 0;
int CC38Fader1Read= 0;
//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
//pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
MIDI.begin(1); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to notes on channel 2 only.
MIDI.setHandleControlChange(MyCCFunction); // This command tells the MIDI Library
// the function you want to call when a Continuous Controller command
// is received. In this case it's "MyCCFunction".
}
void loop() { // Main loop
MIDI.read(); // Continuously check if Midi data has been received.
analogWriteResolution(12);
analogWrite(DAC0, (CC38Fader1Read)+(128*CC6Fader1Read));
}
// MyCCFunction is the function that will be called by the Midi Library
// when a Continuous Controller message is received.
// It will be passed bytes for Channel, Controller Number, and Value
// It checks if the controller number is within the 22 to 27 range
// If it is, light up the corresponding LED with the PWM brightness equal to the Value byte
void MyCCFunction(byte channel, byte number, byte value) {
switch (number) {
case 6:
CC6Fader1Read = value;
break;
case 38:
CC38Fader1Read = value+1;
break;
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Thank for help, I tried a lot of things , I think i have a problème with my midi interface. When Serial received message the RX led in the arduino is light on no? mine don't move, it stay off. |
Beta Was this translation helpful? Give feedback.
-
|
Ok, I solved my communication problem. Now my code works but another problème come. I need to use two Channels per arduino board. With Channel 1 on DAC0 and Channel 2 on DAC1. In one sense its works but not in the other. Let me explain! When I move the fader of my controller n°2, the controller n°1 does not move, It's OK. But when I move the No. 1 controller, the No. 2 also moves. I do not understand why. Do you have an idea? #include <MIDI.h> // Add Midi Library
int CC6Fader1Read = 0;
int CC38Fader1Read = 0;
int CC6Fader2Read = 0;
int CC38Fader2Read = 0;
//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
Serial.begin(31250);
//pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to notes on channel 2 only.
MIDI.setHandleControlChange(MyCCFunction); // This command tells the MIDI Library
// the function you want to call when a Continuous Controller command
// is received. In this case it's "MyCCFunction".
}
void loop() { // Main loop
MIDI.read(); // Continuously check if Midi data has been received.
analogWriteResolution(12);
analogWrite(DAC0, (CC38Fader1Read)+(128*CC6Fader1Read));
analogWrite(DAC1, (CC38Fader2Read)+(128*CC6Fader2Read));
}
void MyCCFunction(byte channel, byte number, byte value) {
switch (channel) {
case 1:
switch (number) {
case 6:
CC6Fader1Read = value;
break;
case 38:
CC38Fader1Read = value+1;
break;
}
case 2:
switch (number) {
case 6:
CC6Fader2Read = value;
break;
case 38:
CC38Fader2Read = value+1;
break;
}
break;
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Ok, Thank you for all, I find my problème, I forgot one "break" in code. Now it work. |
Beta Was this translation helpful? Give feedback.
Ok, Thank you for all, I find my problème, I forgot one "break" in code. Now it work.