Simple 4 fader MIDI controller code

MarkT:
Post your existing code? And circuit?

Thanks Mark, by circuit, do you mean what hardware? I'm using a Teensy 2.0

This code was taken from elsewhere and seems to work for fader 1 (A0), which is transmitting on CC16. There's probably lots of extraneous code in there too.

/* merged different examples for Teensy by Paul Stoffregen
to test MIDI IN & OUT

This example code is in the public domain.
*/
#include <Bounce.h>

const int channel = 1;
Bounce button5 = Bounce(5, 5); // if a button is too "sensitive"

// the MIDI continuous controller for each analog input
const int controllerA0 = 16; // 16 = general purpose

int previousA0 = -1;

elapsedMillis msec = 0;

void setup() {
usbMIDI.setHandleControlChange(OnControlChange);

pinMode(5, INPUT_PULLUP);

}

void loop() {
usbMIDI.read(); // USB MIDI receive
// only check the analog inputs 50 times per second,
// to prevent a flood of MIDI messages

button5.update();
if (button5.fallingEdge()) {
usbMIDI.sendNoteOn(65, 99, channel); // 65 = F4
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOff(65, 0, channel); // 65 = F4
}

if (msec >= 20) {
msec = 0;
int n0 = analogRead(0) / 8;
int n1 = analogRead(1) / 8;
// only transmit MIDI messages if analog input changed
if (n0 != previousA0) {

usbMIDI.sendControlChange(controllerA0, n0, channel);
previousA0 = n0;
}
}
}

void OnControlChange(byte channel, byte control, byte value) {
}