Adding leds to each not

Continuing the discussion from Arduino MIDI Light controller:
i need to add led for each button
each time i press a button the is on and stay on until i press another button
can you help me to do this
this is the sketch for 19 button and one potentiometer

#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();

}

i used it on Leonardo and it is working fine
i will use it on Mega 2560 which i modified to send USB
i have many free pins to use with led out
thanks in advance
NB: originally i got this sketch from post on this forum and i modified it

Hi,
To add code please click this link;

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

1 Like

There are buttons that have built in LED's that illuminates depending on button state. Would such a button make the code simpler and free up GPIO pins for other things?

1 Like

Check the 2560, both pins 0 and 1 are programming pins and should be avoided.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

1 Like