all pins high

Hi

Im just trying to make a transport panel for my project. When i set up the circuit and compile the code every midi note is sent on each button. If i press the play button all the pins go high and arduino sends all the midi notes.

I know that the buttons are not debounced and they need to be but i will cross that bridge later.

Can you see any reason why pins 2 - 6 would all go high?

HARDWARE NOTE:
The MIDI Socket is connected to arduino TX through a PNP transistor to invert the MIDI signal.


################################################################################################
*/
// Arduino pin assignments
#define midiChannel (byte)0
const int playPin = 2;
const int stopPin = 3;
const int recPin = 4;
const int rewPin = 5;
const int ffPin = 6;
byte playNote = 47;
byte stopNote = 48 ;
byte recNote = 49;
byte rewNote = 50;
byte ffNote = 51;
// Start of code
void setup() {
 //  Setup serial
   Serial.begin(31250);    
   pinMode(playPin, INPUT);
   pinMode(stopPin, INPUT);
   pinMode(recPin, INPUT);
   pinMode(rewPin, INPUT);
   pinMode(ffPin, INPUT);
}

//********************* MAIN LOOP ***********************************

void loop() {

if (digitalRead(playPin)== HIGH)
noteSend(0x90,48, 127);
if (digitalRead(stopPin)== HIGH)
noteSend(0x90,49, 127);
if (digitalRead(recPin) == HIGH)
noteSend(0x90,50, 127);
if (digitalRead(rewPin)== HIGH)
noteSend(0x90,51, 127);
if (digitalRead(ffPin)== HIGH)
noteSend(0x90,52, 127);
   
 
    } // end loop function

//********************* Functions *********************************** 


//  plays a MIDI note
 void noteSend(byte cmd, byte data1, byte data2) 
{  
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}

All fo your inputs are connected together because they are all connected to the same pull-down resistor.

As implied, each switch needs its own pulldown resistor.

.

If i press the play button all the pins go high and arduino sends all the midi notes.

Yes that is exactly what that schematic will do.

I can see that easily now.

thanks for your assistance.

I have been looking for my error for a few days on this now. I hope you have not tired of my enquiries.

If you can imagine the same schematic as above, except with every switch having its own pull down resistor, that would save me drawing another schematic.

I have a button class and have created an array of button objects. The code also attempts to debounce the buttons but unfortunately i am getting nothing from it, no midi.

I have a feeling that the debounce function is not setting the message correctly.

Would you mind taking a quick look at it please?

One word of knowledge from the wise saves hours of wasted time for the ignorant.

#include "Controller.h"

//****************************************************************************************


//Button (Pin Number, Command, Note Number, Channel, Debounce Time)
Button::Button(byte pin, byte command, byte value, byte channel, byte debounce)
{
  _pin = pin;
  pinMode(_pin, INPUT);
  _value = value;
  _command = command;
  _debounce = debounce;
  _time = 0;
  _busy = false;
  _status = 0b00000010;
  _last = 1;
  Buttcommand = command;
  Buttvalue = value;
  Buttchannel = channel;
  Butttoggle = 0;
}



byte Button::getValue()
{
  // If BUSY bit not set - read button
  if (bitRead(_status, 0) == false) { // If busy false
    if (digitalRead(_pin) == _last) return 2; // If same as last state - exit
  }

  // If NEW Bit set - Key just pressed, record time
  if (bitRead(_status, 1) == true) { // If new is true
    bitSet(_status, 0); // Set busy TRUE
    bitClear(_status, 1); // Set New FALSE
    _time = millis();
    return 255;
  }

  // Check if debounce time has passed - If no, exit
  if (millis() - _time < _debounce) return 255;

  // Debounce time has passed. Read pin to see if still set the same
  // If it has changed back - assume false alarm
  if (digitalRead(_pin) == _last) {
    bitClear(_status, 0); // Set busy false
    bitSet(_status, 1); // Set new true
    return 255;
  }

  // If this point is reached, event is valid. return event type
  else {
    bitClear(_status, 0); // Set busy false
    bitSet(_status, 1); // Set new true
    _last = ((~_last) & 0b00000001); // invert _last
    return _last;
  }
}

void Button::newValue(byte command, byte value, byte channel)
{
  Buttvalue = value;
  Buttcommand = command;
  Buttchannel = channel;
}

//********************************************************************
#ifndef Controller_h
#define Controller_h

#include <Arduino.h>



//************************************************************************
//Button (Pin Number, Command, Note Number, Channel, Debounce )
class Button
{
  public:
    Button(byte pin, byte command, byte value, byte channel, byte debounce);
    
    byte getValue();
    void newValue(byte command, byte value, byte channel);
    byte Buttcommand;
    byte Buttvalue;
    byte Buttchannel;
    byte Butttoggle;

  private:
    byte _previous;
    byte _current;
    unsigned long _time;
    int _debounce;
    byte _pin;
    byte _value;
    byte _command;
    bool _busy;
    byte _status;
    byte _last;
    byte _enablepin;
};
//*************************************************************************

#endif
#include <MIDI.h>
#include "Controller.h"


MIDI_CREATE_DEFAULT_INSTANCE();


byte NUMBER_BUTTONS = 0;
Button butt1(2, 0x90, 48, 1, 5 );
Button butt2(3, 0x90, 49, 1, 5 );
Button butt3(4, 0x90, 50, 1, 5 );
Button butt4(5, 0x90, 51, 1, 5 );
Button *BUTTONS[] {&butt1, &butt2, &butt3, &butt4};


void setup() {
  MIDI.begin(MIDI_CHANNEL_OFF);
}

void loop() {
updateButts();
  
}

//*****************************************************************
void updateButts() {

  // Cycle through Button array
  for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
    byte message = BUTTONS[i]->getValue();

    //  Button is pressed
    if (message == 0) {
     {
        //note on
      Serial.write(BUTTONS[i]->Buttcommand);
      Serial.write(BUTTONS[i]->Buttchannel);
      Serial.write(BUTTONS[i]->Buttvalue);
      Serial.write(127);   //note on
          
      }
   
 //  Button is not pressed
    if (message == 1) {
      Serial.write(BUTTONS[i]->Buttcommand);
      Serial.write(BUTTONS[i]->Buttchannel);
      Serial.write(BUTTONS[i]->Buttvalue);
      Serial.write(0);   //note off or cc off
      }
    }
  }
  }
      Serial.write(BUTTONS[i]->Buttcommand);
      Serial.write(BUTTONS[i]->Buttchannel);

In MIDI the channel and the command are sent as one byte not two separate ones. The command is the most significant nibble and the channel the least significant nibble. To send something on MIDI channel 1 you actually send the nibble zero.

Why are you writing to the serial port when you have the MIDI libiary? If you want to directly write then there is no need for the MIDI libiary.

MIDI.sendNoteOn(BUTTONS_->Buttvalue, 127, BUTTONS*->Buttchannel);*_
This has cleared that issue up. Thanks for the pointer.