Putting it all together!

Hello everyone,

I'm programming a midi controller with 8 pots (incl. 2 wheels), 2 rotary switches, 3 toggle switches and 4 ribbon controllers.
The codes work separately, with the Moco fo LUFA firmware turning my Atmega8u2 into a midi device (I use the Arduino Mega2560), but I'm having some issues putting everything together.

Basically all midi messages are accurately printed on the serial port but an additional message is printed (with CC value or Note Number 13) after each Control Change or Note On/Off message.
I am guessing something is wrong in the way I have structured the code... I've attached the .pde file because it was too long to post.

Hope one of you almighty programmers will find the time to have a look at it ;).

Cheers!!

Final_Code_4Oct.pde (13.4 KB)

Carriage-return is code 13 - is it your println?

Basically all midi messages are accurately printed on the serial port but an additional message is printed (with CC value or Note Number 13) after each Control Change or Note On/Off message.

The key here is that value (13). That is the ascii code for a carriage return.

void sendNOTEon(byte note, byte vel) {
Serial.print(0x90, BYTE);
Serial.print(note, BYTE);
Serial.println(vel, BYTE);
}

Why are you using println()?

Thanks a lot Awol and PaulS :),
I was using println to see the bytes more easily on the serial port, it all makes sense now!
I'll try the code without the 'ln' later on today.

Ok so it is working now (without the carriage returns) but it doesn't send every value when I turn a potentiometer.
I can hear steps when I sweep a synthesiser parameter up and down. And on the serial port two or three numbers are jumped so I loose a lot of resolution.

Is there a way to increase the speed of the loop or simplify the code?

cheers

Ok so it is working now (without the carriage returns) but it doesn't send every value when I turn a potentiometer.

You should not expect to see every value from 0 to 1023 when you turn a potentiometer.

Mass produced potentiometers are cheaply made. If you get 700 discrete values in the 0 to 1023 range, you've got a good one.

You may be missing values because you are not reading the pot while sending serial data (and you can't - Serial.print() blocks if it is sending more than one byte).

The switch from analogReference(DEFAULT) to analogReference(INTERNAL2V56) takes time, during which you can do nothing.

  delay(20);

doesn't help, either. Nor do any of the other delays.

You should not expect to see every value from 0 to 1023 when you turn a potentiometer.

I am mapping these values to MIDI values (0 to 127). If I didn't have all the delays and AnalogReference changes, would this not ensure that all numbers from 0 to 127 are used? Would dividing instead of mapping be more effective?

If I didn't have all the delays and AnalogReference changes, would this not ensure that all numbers from 0 to 127 are used?

Removing the delays and analogReference calls will not improve the quality of your potentiometer or the speed of serial data transmission or the speed and accuracy of the ADC.

Would dividing instead of mapping be more effective?

Faster, yes. More accurate, no. Divide by 8, or left shift by 3 (faster still).