Hi, i've started experimenting with arduino a couple of weeks ago, my project is a DJ software MIDI controller, i'm using different chunks of code from around for different purposes (rotary encoders, LED outputs, analog ins) i tried different MIDI message handling methods but found the "MIDI library v3.1" Arduino Playground - MIDILibrary the most convenient, now i'm trying to send midi CC values ( MIDI.send(ControlChange,01, rotPotVal, 01)) but i just get 1 message when i move the pot and it stuck until i send a "note on/off" with the rotary encoder. I discovered before that the library won't allow you to repeat the same "note off" or "note on" without its corresponding on/off first, could that be the case with the CCs too? if so, what workaround would you suggest?
Please forgive me if the code is a mess, i'm just experimenting with the small different parts to later unite everything.
Here is the library reference: Arduino MIDI Library: MIDI_Class Class Reference
/* Rotary encoder read example w. midi*/
#include <MIDI.h>
#define ENC_A 8
#define ENC_B 9
#define ENC_PORT PINB
int count;
//X
//connect the middle rotary potentiometer pin to the corresponding Arduino analog ins
//connect the outside rotary potentiometer pins to power and ground
int rotPotIn = 0; //analog in 0
//initial value set to zero
int rotPotVal = 0;
int rotPotValPrev = 0;
//X
void setup()
{
/* Setup encoder pins as inputs */
pinMode(ENC_A, INPUT);
digitalWrite(ENC_A, HIGH);
pinMode(ENC_B, INPUT);
digitalWrite(ENC_B, HIGH);
//initialize MIDI
MIDI.begin();
}
void loop()
{ //X rot encoder
static uint8_t counter = 0; //this variable will be changed by encoder input
int8_t tmpdata;
/**/
tmpdata = read_encoder();
if( tmpdata ) {
//X
if( tmpdata ) {
if( tmpdata == 1 ) {
count++;}
if (count==2){
MIDI.send(NoteOn,40,127,1);
count =0;
MIDI.send(NoteOff,40,0,1);
}
if( tmpdata == -1 ){
count--;}
if (count==-2){
MIDI.send(NoteOn,40,1,1);
count =0;}
MIDI.send(NoteOff,40,0,1);
}
counter += tmpdata;
}
//X Potentiometer
rotPotVal = map(analogRead(rotPotIn), 0, 1023, 0, 127); //read value and remap the range for MIDI
if(abs(rotPotVal-rotPotValPrev)>2){ //only send MIDI messages when value has changed by threshold of 2
MIDI.send(ControlChange,01, rotPotVal, 01); //Chan 1 contol change, controller number, controller value,channel
rotPotValPrev = rotPotVal; //reset value
MIDI.send(
}
//X
}
/* returns change in encoder state (-1,0,1) */
int8_t read_encoder()
{
static int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static uint8_t old_AB = 0;
/**/
old_AB <<= 2; //remember previous state
old_AB |= ( ENC_PORT & 0x03 ); //add current state
return ( enc_states[( old_AB & 0x0f )]);
}