Control.Surface library/Leds on multiplexer.

Hello.
I got this code for switch on/off pedals on amplitube,and light leds.

#include <Control_Surface.h>



USBMIDI_Interface usbmidi; 

// Instantiate a multiplexer
CD74HC4067 mux = {
  34,            // input pin
  {35, 36, 37, 38}, // Address pins S0, S1, S2, S3
  // 7, // Optionally, specify the enable pin
};

CCButtonLatched futton [] = {          /*declarar los pines del multiplexer CD74HC4067 del tipo CCbuttonlatched y con nombre futton*/
  { mux.pin(0), { 90, CHANNEL_1 } },    /* pin C0 del multiplexer en canal uno y con CC90*/
  { mux.pin(1), { 94, CHANNEL_2 } }, 
  { mux.pin(2), { 98, CHANNEL_3 } },     /*todos los botones del multiplexer encienden o apagan cada uno de los 8 pedales que configuremos en nuestro DAW (cubase,amplitube,etc)*/                                               
  { mux.pin(3), { 102, CHANNEL_4 } },
  { mux.pin(4), { 106, CHANNEL_5 } },
  { mux.pin(5), { 110, CHANNEL_6 } },
  { mux.pin(6), { 114, CHANNEL_7 } },
  { mux.pin(7), { 118, CHANNEL_8 } },

// Instantiate a second multiplexer
CD74HC4067 mux2 = {
  8,            // input pin
  {9, 10, 11, 12}, // Address pins S0, S1, S2, S3
  // 7, // Optionally, specify the enable pin
};


const pin_t ledPins[] = { mux2.pin(0), mux2.pin(1), mux2.pin(2), mux2.pin(3), mux2.pin(4), mux2.pin(5), mux2.pin(6), mux2.pin(7) };

template <class T, size_t N> constexpr size_t length(T (&)[N]) { return N; }

static_assert(length(futton) == length(ledPins),
              "Error: requires same number of buttons as LEDs");

void setup() {

    Control_Surface.begin();
 for (auto pin : ledPins)  // Set the pinMode to output for all LEDs
      pinMode(pin, OUTPUT);

 }

void loop() {
  // put your main code here, to run repeatedly:
  Control_Surface.loop();
 for (size_t i = 0; i < length(futton); ++i)
      // Update the LED states to reflect the toggled switch states
      digitalWrite(ledPins[i], futton[i].getState() ? HIGH : LOW);
}

No problem when i use normal pins on arduino mega for light leds..but my problem it´s connecting leds on multiplexer.
How could i write the previous code for lightning leds on multiplexer mux2.?
Thanks.

You cannot use multiplexers to drive LEDs (well at least not without scanning through the channels really quickly to create a persistence of vision effect).

Multiplexers are usually not the right choice for driving LEDs, which is why Control Surface doesn't support it.

If you need to drive more LEDs than you have Arduino pins, you could use shift registers, dedicated LED drivers, IO expanders like the MCP23017 or addressable LEDs. Personally, I prefer shift registers, they're easy to use and really fast to update over SPI. You can get them with built-in LED drivers so you don't even need current limiting resistors in that case.

Pieter

Thanks Pieter.
Shift registers maybe will be my best option... but i don´t know..i got one question about shift registers..
so..You press the button one time and the led will light on...and then press again and will light off the led..theres no comunication between daw and press buttons..only pressing button you switch on/off the led?

In that case i think i will go forward in my project using arduino pins for the leds..and i will use a multiplexer for latched buttons or pots..no leds

My best option,for sure, would be ws2812b..but i am not able to drive this leds yet.. like now i do with capsulated rgb leds and the first post code ..

I want to finish soon my footswitch and show it

chichiforever:
Shift registers maybe will be my best option... but i don´t know..i got one question about shift registers..
so..You press the button one time and the led will light on...and then press again and will light off the led..theres no comunication between daw and press buttons..only pressing button you switch on/off the led?

What's your question? How you're driving the LEDs is completely independent from whether you're using MIDI to communicate with the DAW or not.

My best option,for sure, would be ws2812b..but i am not able to drive this leds yet..

Why not?
They're not a good option if you want to be able to use MIDI input on an AVR device. While writing data to the LEDs, interrupts are disabled and MIDI data will be dropped.

What's your question? How you're driving the LEDs is completely independent from whether you're using MIDI to communicate with the DAW or not.

I mean to update the LED states to reflect the toggled switch states..
The first post there its a code (i bringed from this forum.i am not sure you wrote it)

Shift registers doesn´t do this thing..i think..

I prefer to reflect the real on or off in pedals state..so...the toggled switch states reflects the real state(now i understand theres its no comunication between midi and daw..thanks)

English it´s difficult to me..i hope you understand

Why not?
They're not a good option if you want to be able to use MIDI input on an AVR device. While writing data to the LEDs, interrupts are disabled and MIDI data will be dropped

Rainbow or scanner (or theatre chase) are animation effects on ws2812b leds..
There its no chance to use this animations on a midi arduino device.

But there its a chance, i think,to use this leds and no lagging on midi..
You light one colour on one led..no more..
Its easy to wire up ws2812b leds and its better solutions than my encapsulated rgb leds..

I am on early stages right now and i hope to be able to light ws2812b leds as i want..
But now i need to finish the footwitch (yesterday postman bringed me a i2c 20x4 lcd screen..)

I want to thank you peter, your help its very apprecciated.

chichiforever:
I mean to update the LED states to reflect the toggled switch states..
The first post there its a code (i bringed from this forum.i am not sure you wrote it)

That does look like code I would write.

chichiforever:
Shift registers doesn´t do this thing..i think..

Why not? If you add using namespace ExtIO; at the top of your sketch, the same code should work with the shift register classes of Control Surface as well.

chichiforever:
Rainbow or scanner (or theatre chase) are animation effects on ws2812b leds..
There its no chance to use this animations on a midi arduino device.

Is this a statement or a question? You can use WS2812 if you only need MIDI output and no input, or if you have a board that's fast enough. MIDI input on AVR-based Arduino boards won't work reliably with WS2812 LEDs.

chichiforever:
But there its a chance, i think,to use this leds and no lagging on midi..
You light one colour on one led..no more..

I doubt it, see Interrupt problems · FastLED/FastLED Wiki · GitHub.

Is this a statement or a question? You can use WS2812 if you only need MIDI output and no input, or if you have a board that's fast enough. MIDI input on AVR-based Arduino boards won't work reliably with WS2812 LEDs.

I am trying to understand..
Ok..but uploading some ws2812 animations on an arduino uno...there its a chance to use them conecting to a control.surface device..using two arduinos..
But thats not the point for me right now..i am working on encapsulated rgb leds..thanks for the advice on ws2812..i will try in a future anyway..
Now i got this code..only light up the first led, red colour, on 6 ledstrip (ws2812)

#include <Control_Surface.h>
USBMIDI_Interface usbmidi;
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

//Designamos nuestro pin de datos
#define PIN 40
//Designamos cuantos pixeles tenemos en nuestra cinta led RGB
#define NUMPIXELS      6


void setup() {
   Control_Surface.begin();
   pixels.begin();

}


void loop() {
  Control_Surface.loop();
 
   uint32_t rojo = pixels.Color(150,0,0);
  
 pixels.setPixelColor(0, rojo); // Brillo moderado en rojo en el pixel numero 1 de nuestra tira de 6 leds

 pixels.show();   // Mostramos y actualizamos el color del pixel de nuestra cinta led RGB

Why not? If you add using namespace ExtIO; at the top of your sketch, the same code should work with the shift register classes of Control Surface as well.

Ok..i see an example on your tutorial,getting started, i will try this right now, but i am confused because i was thought that shift registers only light leds when you press the button twice times..ok..sorry..
Let me show you the code i got for light leds with pedals (i got another leds for banks)..
So in this code,pins ( 38, 39, 40, 41, 42, 43, 44, and 45 ) check for a button if its pressed and light the led.
The buttons are in mux2 pins ( 8, 9, 10, 11, 12, 13, 14 and 15 ).

The point for me right now its to do the same on SPI shift-registers.
I have got two 74hc595..and are correctly wired (following your tutorial)..so i write this code..

#include <Control_Surface.h>  /*Program--include library-- then select "control surface" library..Vamos a programar el codigo con la librería Control Surface*/
USBMIDI_Interface usbmidi;    /*initializes device as usb_midi interface...see other examples like hardwareserial,hairles etc*/
#include <Arduino_Helpers.h> // Include the Arduino Helpers library.
#include <AH/Containers/ArrayHelpers.hpp>
#include <AH/Hardware/Button.hpp>
#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>
#include <AH/Hardware/ExtendedInputOutput/SPIShiftRegisterOut.hpp>


Bank<8> bankpedal(4);  /*El bank tiene 4 posiciones o 4 ajustes de banco posibles <4> y se llama bank y tiene un rango de cuatro (4) por lo 
                     tanto crecerá o decrecerá cuatro valores*/
Bank<8> bankamp(4);  /*El bank tiene 4 posiciones o 4 ajustes de banco posibles <4> y se llama bank2 y tiene un rango de cuatro (4) por lo 
                     tanto crecerá o decrecerá (4) valores*/
// Instantiate a multiplexer
CD74HC4067 mux = {
  15,            // input pin
  {2, 3, 4, 14}, // Address pins S0, S1, S2, S3
  // 7, // Optionally, specify the enable pin
};
// Instantiate a shift register with the SPI slave select pin as latch pin, most
// significant bit first, and a total of 16 outputs.
SPIShiftRegisterOut<mux.length()> sreg = {SS, MSBFIRST};

auto buttons = generateIncrementalArray<Button, mux.length()>(mux.pin(0));

// Instantiate a multiplexer
CD74HC4067 mux2 = {
  8,            // input pin
  {9, 10, 11, 12}, // Address pins S0, S1, S2, S3
  // 7, // Optionally, specify the enable pin
};

CCButtonLatched futton2 [] = {          /*declarar los pines del multiplexer CD74HC4067 del tipo CCbuttonlatched y con nombre futton*/
  { mux2.pin(0), { 90, CHANNEL_1 } },    /* pin C0 del multiplexer en canal uno y con CC90*/
  { mux2.pin(1), { 94, CHANNEL_2 } }, 
  { mux2.pin(2), { 98, CHANNEL_3 } },     /*todos los botones del multiplexer encienden o apagan cada uno de los 8 pedales que configuremos en nuestro DAW (cubase,amplitube,etc)*/                                               
  { mux2.pin(3), { 102, CHANNEL_4 } },
  { mux2.pin(4), { 106, CHANNEL_5 } },
  { mux2.pin(5), { 110, CHANNEL_6 } },
  { mux2.pin(6), { 114, CHANNEL_7 } },
  { mux2.pin(7), { 118, CHANNEL_8 } },
 }; 


CCButtonLatched futton [] = {  
  { mux2.pin(8), { 91, CHANNEL_1 } },    
  { mux2.pin(9), { 92, CHANNEL_2 } }, 
  { mux2.pin(10), { 93, CHANNEL_3 } },                                                   
  { mux2.pin(11), { 95, CHANNEL_4 } },
  { mux2.pin(12), { 96, CHANNEL_5 } },
  { mux2.pin(13), { 97, CHANNEL_6 } },
  { mux2.pin(14), { 99, CHANNEL_7 } },
  { mux2.pin(15), { 100, CHANNEL_8 } },

};

// Instantiate a multiplexer
CD74HC4067 mux3 = {
  A15,            // input pin
  {A11, A12, A13, A14}, // Address pins S0, S1, S2, S3
  // 7, // Optionally, specify the enable pin
};

Bankable::CCButtonLatched<8>  bankbuttons [] = {  /*declarar los botones que creceran o decreceran (4) valores dentro de cada cambio de banco.Serán del tipo ccbuttonlatched,se llamarán bankbuttons y los declaramos como bankables en los pines de salida 5 y 6 de arduino con los CC90 Y CC91 */
  { bankpedal, 5, 90, },  
  //{ bankpedal, 6, 91, },
  };

Bankable::CCPotentiometer pots[] = {    /*declarar los potenciometros que creceran o decreceran (4) valores dentro de cada cambio de banco.Serán del tipo ccpotentiometer,se llamarán pots y los declaramos como bankables en los pines analogicos de salida A0,A1..ETC..de arduino con los CC66,CC67..ETC*/
  
  {bankpedal, mux3.pin(8), 66},
  {bankpedal, mux3.pin(9), 67},
  {bankpedal, mux3.pin(10), 68},
  {bankpedal, mux3.pin(11), 69},
  {bankpedal, mux3.pin(12), 1},
  {bankpedal, mux3.pin(13), 2},
  {bankpedal, mux3.pin(14), 3},
  {bankpedal, mux3.pin(15), 4},
  };
 
Bankable::CCPotentiometer pots2[] = {    /*declarar los potenciometros que creceran o decreceran (4) valores dentro de cada cambio de banco.Serán del tipo ccpotentiometer,se llamarán pots y los declaramos como bankables en los pines analogicos de salida A0,A1..ETC..de arduino con los CC66,CC67..ETC*/
  
  {bankamp, mux3.pin(0), 74},
  {bankamp, mux3.pin(1), 75},
  {bankamp, mux3.pin(2), 76},
  {bankamp, mux3.pin(3), 77},
  {bankamp, mux3.pin(4), 78},
  {bankamp, mux3.pin(5), 79},
  {bankamp, mux3.pin(6), 80},
  {bankamp, mux3.pin(7), 80},
  };
IncrementDecrementSelectorLEDs<8> bankSelector = {   /*declarar lo botones que van a incrementar o decrecer la posicion del cambio de banco dentro del banco llamado bank..como tiene cuatro bancos posibles..declaramos cuatro led pins para saber la posición del banco en el que estamos. Los botones  que nos permitiran cambiar el banco serán los pines 2 y 3 en arduino*/
  bankpedal,
  {6, 7},         // button pins
  {22, 27, 24, 29, 26, 23, 28, 25}, // LED pins
  }; 

IncrementDecrementSelectorLEDs<8> bankSelector2 = {   /*declarar lo botones que van a incrementar o decrecer la posicion del cambio de banco dentro del banco llamado bank2..como tiene cuatro bancos  posibles..declaramos cuatro led pins para saber la posición del banco en el que  estamos. Los botones que nos permitiran cambiar el banco serán los pines 2 y 3 en  arduino*/
  bankamp,
  {19, 18},         // button pins
  {30, 31, 32, 33, 34, 35, 36, 37}, // LED pins
  };



const pin_t ledPins[] = { 38, 39, 40, 41, 42, 43, 44, 45 };

template <class T, size_t N> constexpr size_t length(T (&)[N]) { return N; }

static_assert(length(futton) == length(ledPins),
              "Error: requires same number of buttons as LEDs");


void setup() {

    Control_Surface.begin();
 for (auto pin : ledPins)  // Set the pinMode to output for all LEDs
      pinMode(pin, OUTPUT);

  mux.begin();
  sreg.begin();
  for (Button &button : buttons)
    button.begin();
 }

void loop() {
  // put your main code here, to run repeatedly:
  Control_Surface.loop();
 for (size_t i = 0; i < length(futton); ++i)
      // Update the LED states to reflect the toggled switch states
      sreg.digitalWrite(ledPins[i], futton[i].getState() ? HIGH : LOW);

  // Check if a button is pressed, if so toggle the LED
  for (uint8_t i = 0; i < mux.length(); ++i)
    if (buttons[i].update() == Button::Falling)
      sreg.digitalWrite(i, sreg.digitalRead(i) ? LOW : HIGH);
}

I doubt it, see Interrupt problems · FastLED/FastLED Wiki · GitHub.

A cheap solution for this would be to use a wemos d1 mini pro..but I am not interested on ws2812 leds right now

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