Hello! Im currently near finishing my MIDI controller! However... I have only managed to have 4 MIDI drum pads working if they ARENT velocity sensitive. I have the code to make one piezo velocity sensitive, but Im not very good at arrays and am struggling to implement one. Everytime I change something it says something else isnt declared - when it worked quite happily before the array!
This is the original code:
#include <MIDI.h>
const int piezo = A9;
int threshold = 50; //anything over fifty means we've hit the piezo
void setup(){
MIDI.begin(1);
}
void loop(){
int sensorReading = analogRead(piezo);
if (sensorReading >= threshold){
int maxPiezoVal = getMaxVal(sensorReading);
byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
MIDI.sendNoteOn(50, velocity, 1);
delay(10);
MIDI.sendNoteOff(50, 0, 1);
delay(100);
}
}int getMaxVal(int lastVal){
int currentVal = analogRead(piezo);
while (currentVal>lastVal){
lastVal = currentVal;
currentVal = analogRead(piezo);
}return lastVal;
}
And this is what I have done, which I know is wrong but I gave it a go :
#include <MIDI.h>
int piezo[4] = {A9, A10, A11, A12};
#define inputs 4
int note[4] = {50, 51, 52, 53};
int threshold = 50; //anything over fifty means we've hit the piezovoid setup(){
MIDI.begin(1);
}
void loop(){
for(int i=0; i<inputs; i++) {
int sensorReading = analogRead(i);
if (sensorReading >= threshold){
int maxPiezoVal = getMaxVal(sensorReading);
byte velocity = map(maxPiezoVal, 0, 1023, 0, 127);//velocity between 50 and 127 based on max val from piezo
MIDI.sendNoteOn(note*, velocity, 1);*
- delay(10);*
_ MIDI.sendNoteOff(note*, 0, 1);_
_ delay(100);_
_ }_
_}*_int getMaxVal(int lastVal) {
* int currentVal = analogRead(i);*
* while (currentVal>lastVal){*
* lastVal = currentVal;*
* currentVal = analogRead(i);*
* }*
return lastVal;
}
}
[/quote]
Would someone be able to tell me where Im going wrong please? I really need this finished by tomorrow night so in a bit of a panic I just need four velocity sensitive drum pads!
I appreciate any help that anyone can give me. Thanks!