Add led to midi buttons sketch

Dear members
i am new to this forum i have got this sketch from a member here.
the sketch is MIDI-USB for 19 buttons and one potentiometer

i am using Arduino Mega 2560 and i have many empty pins on it
i need to add to this sketch led control for buttons only
when i press a button the led is on and stay only until i press another button and so on
this is the sketch:

#include <MIDI_Controller.h> // Include the library

const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t channel = 1; // MIDI channel 1

// Create an array of 19 new instances of the class 'Digital', called 'buttons',
// on pins 0, 1, ..., 11, 12, 13, A1, A2, A3, A4, A5 that send MIDI messages with notes
// 60, 61, ..., 71, 72, 73, 74, 75, 76, 77, 78 on MIDI channel 1, with maximum velocity (127)
Digital buttons[] = {
{ 0, 60, channel, velocity }, // button connected to pin 0, sends MIDI note 60 (C3) on channel 1 with velocity 127
{ 1, 61, channel, velocity },
{ 2, 62, channel, velocity },
{ 3, 63, channel, velocity },
{ 4, 64, channel, velocity },
{ 5, 65, channel, velocity },
{ 6, 66, channel, velocity },
{ 7, 67, channel, velocity },
{ 8, 68, channel, velocity },
{ 9, 69, channel, velocity },
{10, 70, channel, velocity },
{11, 71, channel, velocity },
{12, 72, channel, velocity },
{13, 73, channel, velocity },
{A1, 74, channel, velocity },
{A2, 75, channel, velocity },
{A3, 76, channel, velocity },
{A4, 77, channel, velocity },
{A5, 78, channel, velocity },
};

// Create an array of 1 new instances of the class 'Analog', called 'potentiometers',
// on pins A0 that send MIDI CC messages with controller numbers 16
// on MIDI channel 1
Analog potentiometers[] = {
{ A0, 16, channel }, // potentiometer connected to pin A0, sends CC (Control Change) #16 on MIDI channel 1

};

void setup() {} // nothing to set up

void loop() { // Refresh the buttons and potentiometers (check whether a button's state or a potentiometer's position has changed since last time, if so, send it over MIDI)
MIDI_Controller.refresh();
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

So what have you tried ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.