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;
}