Piezo Velocity for MIDI Drums - Help Needed

Hi people, ive been working on my MIDI controller, which currently is reading a total of 6 analogue inputs, 4 piezos and 2 potentiometers. ive got the following code below but have absolutely no idea how would go about making the piezos velocity sensitive. I am very new to coding so dont really know where to start, has anyone ever done anything like this before with success or would know anything to help? thanks.

#include <Bounce.h>

// define how many pots are active up to number of available analog inputs
#define analogInputs 2

// make arrays for input values and lagged input values
int inputAnalog[analogInputs];

int iAlag[analogInputs];

// make array of cc values
int ccValue[analogInputs];

// index variable for loop
int i;


void setup() {
  // MIDI rate
  Serial.begin(31250);
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
}

void loop() {
 
  // loop trough active inputs for knobs
  for (i=0;i<analogInputs;i++){
   
    // read current value at i-th input
    inputAnalog[i] = analogRead(i);
   
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 7){
    
      // calc the CC value based on the raw value
      ccValue[i] = inputAnalog[i]/8;
     
      // send the MIDI
      usbMIDI.sendControlChange(i, ccValue[i], 3);
     
      // set raw reading to lagged array for next comparison
      iAlag[i] = inputAnalog[i];
    }
  delay(5); // limits MIDI messages to reasonable number
  
  
  
  }



  
 
  
}

I'm not a MIDI expert and I'm not really following your code... I can give you a couple of suggestions, but I can't help you with the details.

I suggest you start simple and just read one piezo. Then after that works, add code little bits at a time, testing as you go-along.

It looks to me like you're reading digital inputs, and I don't think the internal pull-ups work with analog. Plus, with analog pots you don't need pull-ups and with piezos you'll want a pull-down (I'm guessing 1M Ohm).

There's no need to take the absolute value, since the analog-to-digital converter doesn't give negative values. (The negative half of the piezo waveform will be "shorted out" by the diodes inside the ATmega chip. Normally you don't want to feed-in negative voltages, but a piezo doesn't put-out enough current to damage the Arduino... Hopefully...)

Use the serial monitor to check your analog readings (similar to the [u]Analog Read Serial Example[/u]). Once you know what values you're getting from the piezos, [u]map()[/u] those values to 0-127 velocity values.

That might a little tricky, because you need to "catch" the peak. if you set the velocity as soon as you pick-up something you might not get the full-peak value.

You are only making the ccValue array two elements, you need one element for each sensor.

This is not code for an Arduino, it is for a Teensey, you could try asking on the Teensey forums.

Edit:- pull up resistors do work with analogue inputs. Cut out all that input pull up stuff you don't need it. Especially on pins 0 & 1 which are the serial pins.