Radio button style midi controller

Hey all

I'n a little stuck with simplifying a part iof my project and hope someone can help.

I'm building a 10 button midi controller with an arduino mega. This controller sends one message per momentry button, lights the corresponding led and only one button is active at a time (so the other leds go out)

I've seen a sketch online on the hackersrus site and it works for what I want but.....

There a lots and lots of wires and I just dont have enough room in my enclosure and I cant make it any bigger as its fitting in an existing case.

I've seen a sketch online about radio buttons MD on wordpress. It turns pins from inputs to outputs. This would literally 1/4 the components and wires needed to achieve the same goal.

I have bread boarded and uploaded the sketch and the radio buttons work as buttons and light the leds to light.

I have added a when x pin is pressed serial print "x button pressed"

And I've monitored it in my serial monitor in arduino program.

The problem I am having it that it will only send the message after a short delay, which is not what I need.

In the serial monitor it does print the "address" (I guess that what it's called) that the radio button is using 0 1 2 or 3 all the time.

So my questions are

How can I use that number that is generated by the radio button to then trigger it to send my message (or midi command)

Is there another way that I can do it, to keep component and wireing easy. I'm a bit of a novice at this (bet you can tell)

Thanks in advance. P.s. sketch I'm working on is uploaded in the next post.

Baz

Do you think that it might help if you posted your sketch, using code tags when you do, and a schematic of your project ?

// Example showing use of the MD_RadioButton library
//
#include <MD_RadioButton.h>


#define USE_CALLBACK  0

uint8_t pinArray[] = { 22, 23, 24, 25 };

MD_RadioButton  RB(ARRAY_SIZE(pinArray), pinArray);

void cbNotify(uint8_t sel)
// Callback funtion (when enabled)
{
  Serial.println(sel);
}

void setup() 
{
  Serial.begin(9600);
  
  RB.begin();
  RB.lampTest();

#if USE_CALLBACK
  Serial.println("Callback enabled");
  RB.setCallback(cbNotify);
#endif // USE_CALLBACK

  RB.select(0); // selects what radio button is at the start
}

void loop() 
{
#if USE_CALLBACK
  RB.read();
#else
  uint8_t sel;

  if ((sel = RB.read()) != NO_SELECT)
    Serial.println(sel);
#endif

if(digitalRead(22) == LOW){
    Serial.println(" 22 pressed.");
  }
    if(digitalRead(23) == LOW){
    Serial.println("23 pressed.");
  }
  if(digitalRead(24) == LOW){
    Serial.println("24 pressed.");
  }
  if(digitalRead(25) == LOW){
    Serial.println("25 pressed.");
  }
}

radiobutton-schematic.png

UKHeliBob:
Do you think that it might help if you posted your sketch, using code tags when you do, and a schematic of your project ?

Sorry was just on my way up to the pc