MIDI controller constant TX messages..

Having problems with my MIDI controller! The controller has 12 push buttons, 6 pots and 4 velocity sensitive drum pads. They all work separately but when I put them together there is constant TX messages. When putting the MIDI in Ableton its creating an arpeggiated sound. My problem is Ive just bunged all the code together and it verified so hoped it worked. It worked when the pots and buttons were together but think the drum pads have caused a problem:

Buttons are Digital pins 2-13
Pots are analog pins 0-5
Drum pads are analog pins 9-12

Ive attached the file because there isnt enough words available to post the code - its that unorganised!

If anyone knows where my problem lies I’d appreciate the help

project.ino (9.86 KB)

int buttonPin1 = 2;               //choose the input pin for a pushbutton
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonPin6 = 7;
int buttonPin7 = 8;
int buttonPin8 = 9;
int buttonPin9 = 10;
int buttonPin10 = 11;
int buttonPin11 = 12;
int buttonPin12 = 13;

Arrays. You need to study array. You have 12 times as much code as you need.

  buttonVal1 = digitalRead(buttonPin1);     //read input value from button
  delay(10);                              //wait 10ms
  bounceCheck = digitalRead(buttonPin1);   //check again
  if(buttonVal1 == bounceCheck){           //if val is the same then not a bounce
    if (buttonVal1 == LOW && buttonState1 == 1) {   //check if the input is LOW

Names like currState and prevState make a lot more sense. Comparing one reading to LOW and the other reading to 1 makes no sense.

You haven't said anything about how your switches are actually wired.

I know Ive made it complicated for myself! But when I wrote the button sketch I was at the start of the project and new nothing. Although the code doesnt need to be that long and complicated it still works. Its just whens Ive added the drum pads into the equation.

The buttons are wired with a pull up resistor like in this tutorial http://www.roguescience.org/wordpress/building-a-midi-out-controller/part-3-add-a-switch/exercise-6/

The piezos are conditioned like the attached image

piezocond.jpg

Is this better?

#include <MIDI.h>
#include “Arduino.h”
void sendMidi(char chan, char val);

//buttons

const int buttonCount = 12;
int buttonPin[buttonCount] = {2,3,4,5,6,7,8,9,10,11,12,13};
int buttonVal[buttonCount] = {0};
int buttonState[buttonCount] = {0};
int bounceCheck = 0;

//pots

#define inputs 6
#define e 1 // this is the delta needed in
// currentPot to send a message

*int currentPot[6] = {0,0,0,0,0,0}; *
int pot[6] = {0,0,0,0,0,0};
int channel[6] = {1,2,3,4,5,6};
//piezos
const int InputCount = 4;
int piezo[InputCount] = {A9, A10, A11, A12};
int note[InputCount] = {50, 51, 52, 53};
const int threshold = 100; //anything over fifty means we’ve hit the piezo
void setup() {

for (byte i = 2; i >= 13; i++) {
_ pinMode(buttonPin*, INPUT);_
_
Serial.begin(31250); //MIDI communicates at 31250 baud*_
* MIDI.begin(1);*
}
}
void loop(){

//buttons
for (byte i=0; i >= 11; i++) {
buttonVal = digitalRead(buttonPin*); //read input value from button*
* delay(10); //wait 10ms*
_ bounceCheck = digitalRead(buttonPin*); //check again*
if(buttonVal == bounceCheck){ //if val is the same then not a bounce_

if (buttonVal == LOW && buttonState == 1) { //check if the input is LOW

* MIDI.sendNoteOn (60, 127, 1); // Note ON (CH 1), middle C, velocity 127*
_ buttonState = 0;
* }*_

if(buttonVal == HIGH && buttonState == 0){ //check if the button is HIGH

* MIDI.sendNoteOff (60, 0, 1);; //Note ON (CH 1), middle C, velocity 0*
_ buttonState = 1;
* }
}
}*_

* //pots*
* for(int i=0; i<inputs; i++) {*
_ currentPot = analogRead(i) / 8;
if(abs(currentPot-pot) > e) {

sendMidi(channel, currentPot*);_
pot _= currentPot;
}
}*_

* //drum pads*

* 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*
* MIDI.sendNoteOn(note[0], velocity, 1);*
* delay(10);*
* MIDI.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*
* MIDI.sendNoteOn(note[1], velocity, 1);*
* delay(10);*
* MIDI.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*
* MIDI.sendNoteOn(note[2], velocity, 1);*
* delay(10);*
* MIDI.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*
* MIDI.sendNoteOn(note[3], velocity, 1);*
* delay(10);*
* MIDI.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;*
}
//send pots
void sendMidi(char chan, char val) {
* Serial.write(0xB0);*
* Serial.write(chan);*
* Serial.write(val);*
}
Not sure if it works though because theres still the problem with the constant TX :frowning:

Is this better?

No. That is not posted correctly. I'm sure your code doesn't actually look like that.

Put the switches in a drawer. Put the piezos in a drawer. Put 5 or the 6 drum pads in a drawer. Get the sketch working with ONE drum pad. Get it talking to the Serial Monitor, not to a MIDI device. Then, you can put the other stuff back.

Thanks for your advice, but I re soldered all the circuit and finished the controller yesterday. And it works.

Only problem is the drum pads arent as sensitive when the code is put all together. However the code on its own works perfectly.

So back to my original question - is there a way to put the code together that makes this happen/is there some conflicting code thats confusing it that I cannot understand?

Despite the code not being efficient the buttons and pots work perfectly. For my first Arduino project Im really happy!