Potentiometer MIDI Control Change

Hi Guys, im building a MIDI controller for part of my final year project, i have 5 piezo transducers which will be triggering drum samples via midi. I have the piezo code written which i think works however i want to add 2 analogue potentiometer inputs which would send midi control change information to a DAW. im using an arduino Teensy 2.0 which has the MIDI.sendControlChange function however im fairly new to coding so am unsure how i would add this to the existing code. Any help would be appreciated! cheers guys

#include <Bounce.h>

//code takes inputs from 5 piezos and mapps velocity

// PIEZOS 

const int InputCount = 5;
int piezo[InputCount] = {
  A0, A1, A2, A3, A4};
int note[InputCount] = {
  50, 51, 52, 53, 54};


const int threshold = 50; //anything over fifty means we've hit the piezo

void setup() {
  Serial.begin(31250);
}

void loop() {
  
  //DRUMPADS 
  
  int sensorReading;

  sensorReading = analogRead(piezo[0]);
  if (sensorReading >= threshold) {
    int maxPiezoVal = getMaxVal(piezo[0], sensorReading);
    byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
    usbMIDI.sendNoteOn(note[0], velocity, 1);
    delay(10);
    usbMIDI.sendNoteOff(note[0], 0, 1);
    delay(100);
  }

  sensorReading = analogRead(piezo[1]);
  if (sensorReading >= threshold) {
    int maxPiezoVal = getMaxVal(piezo[1], sensorReading);
    byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
    usbMIDI.sendNoteOn(note[1], velocity, 1);
    delay(10);
    usbMIDI.sendNoteOff(note[1], 0, 1);
    delay(100);
  }

  sensorReading = analogRead(piezo[2]);
  if (sensorReading >= threshold) {
    int maxPiezoVal = getMaxVal(piezo[2], sensorReading);
    byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
    usbMIDI.sendNoteOn(note[2], velocity, 1);
    delay(10);
    usbMIDI.sendNoteOff(note[2], 0, 1);
    delay(100);
  }

  sensorReading = analogRead(piezo[3]);
  if (sensorReading >= threshold) {
    int maxPiezoVal = getMaxVal(piezo[3], sensorReading);
    byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
    usbMIDI.sendNoteOn(note[3], velocity, 1);
    delay(10);
    usbMIDI.sendNoteOff(note[3], 0, 1);
    delay(100);
  }

  sensorReading = analogRead(piezo[4]);
  if (sensorReading >= threshold) {
    int maxPiezoVal = getMaxVal(piezo[4], sensorReading);
    byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
    usbMIDI.sendNoteOn(note[3], velocity, 1);
    delay(10);
    usbMIDI.sendNoteOff(note[3], 0, 1);
    delay(100);
  }

}

int getMaxVal(int pin, int lastVal) {
  int currentVal = analogRead(pin);
  while (currentVal>lastVal){
    lastVal = currentVal;
    currentVal = analogRead(pin);
  }
  return lastVal;
}

At what point in the code do you want the CC to go out? Before or after reading the sensors? Or in the middle of them? At that point in the code, take the reading from the pot, do whatever math might be necessary to make it a sensible number for a CC message, and send it.

hi, i was thinking of having the potentiometer code after the piezo code but am not sure how i go about reading the analogue inputs and sending the control change values?

Well you posted the command to send the CC message in the first post. If you read the doc for that it surely tells what arguments you need to provide with it.

To read the pot value go have a look at the analogRead function. It's in the Arduino reference and isn't hard to understand at all.

Finally to scale the analogue read value into a CC value you can use the map function.