Final touch the project

Good afternoon everyone.
This is my first project with Arduino after days eating my head and gotten here, it works well for me but it lacks the final touch.

It would be possible that the LEDs were always on and when the DAW sent me the signal it would start to blink, and I read the entire "control surface" library but I can't find it anywhere.
I do not know if it is possible or my ideas go beyond reality.

What does that mean?

Please, just post your code.
In code tags

#include <Control_Surface.h> // Include the Control Surface library
 
// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;
 
// Instantiate a CCButton object
CCButton button  {0,{MIDI_CC::General_Purpose_Controller_1, CHANNEL_1},};
CCButton button1 {1,{MIDI_CC::General_Purpose_Controller_2, CHANNEL_1},};
CCButton button2 {2,{MIDI_CC::General_Purpose_Controller_3, CHANNEL_1},};
CCButton button3 {3,{MIDI_CC::General_Purpose_Controller_4, CHANNEL_1},};
CCButton button4 {4,{MIDI_CC::General_Purpose_Controller_5, CHANNEL_1},};
CCButton button5 {5,{MIDI_CC::General_Purpose_Controller_6, CHANNEL_1},};
CCButton button6 {6,{MIDI_CC::General_Purpose_Controller_7, CHANNEL_1},};
// Instantiate the LED that will light up when middle C is playing
CCLED led1 {7, {MIDI_CC::General_Purpose_Controller_1, CHANNEL_1},};
CCLED led2 {8, {MIDI_CC::General_Purpose_Controller_2, CHANNEL_1},};
CCLED led3 {9, {MIDI_CC::General_Purpose_Controller_3, CHANNEL_1},};
CCLED led4 {10, {MIDI_CC::General_Purpose_Controller_4, CHANNEL_1},};
CCLED led5 {11, {MIDI_CC::General_Purpose_Controller_5, CHANNEL_1},};
CCLED led6 {12, {MIDI_CC::General_Purpose_Controller_6, CHANNEL_1},};
CCLED led7 {13, {MIDI_CC::General_Purpose_Controller_7, CHANNEL_1},};
// Setup for an Analog pot
CCPotentiometer potentiometer {A0, {MIDI_CC::Sound_Controller_1, CHANNEL_1}};
CCPotentiometer potentiometer1 {A1, {MIDI_CC::Sound_Controller_2, CHANNEL_1}};
CCPotentiometer potentiometer2 {A2, {MIDI_CC::Sound_Controller_3, CHANNEL_1}};
CCPotentiometer potentiometer3 {A3, {MIDI_CC::Sound_Controller_4, CHANNEL_1}};
CCPotentiometer potentiometer4 {A4, {MIDI_CC::Sound_Controller_5, CHANNEL_1}};
CCPotentiometer potentiometer5 {A5, {MIDI_CC::Sound_Controller_6, CHANNEL_1}};


void setup() {
  Control_Surface.begin(); // Initialize Control Surface

}
 
void loop() {
  Control_Surface.loop(); // Update the Control Surface
}

I think the translator played me a bad pass

Read the forum guidelines.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Edit your post to include code tags on the code. To do so, select (highlight) the code and click on the </> in the menu bar. It is that simple.

Thanks

It's unclear to me what exactly you're after: Do you want your CCLEDs to blink instead of being full on/off? Or do you want some kind of activity LED that blinks when there's MIDI being sent or received?

Good morning Piter.P., First of all thank you for the wonderful library.
secondly, so that we understand each other, I use this with a voice program that marks me silence in ccled when it is active,
the intention is that the ccled is always on, and when you silence the ccled it starts to blink.

Thanks for taking your time greetings

You could try something like this:

#include <Control_Surface.h>

USBMIDI_Interface midi;

class CustomCCLED : public MatchingMIDIInputElement<MIDIMessageType::CONTROL_CHANGE,
                                                    TwoByteMIDIMatcher> {
 public:
  CustomCCLED(pin_t ledPin, MIDIAddress address, unsigned long blinkInterval = 250)
    : MatchingMIDIInputElement(address), ledPin(ledPin), blinkTimer(blinkInterval) {}

  void begin() override { // Called once in setup
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, HIGH);
  }
  void handleUpdate(TwoByteMIDIMatcher::Result match) override { // Called when MIDI message received for this address
    blinking = match.value > 0;
    if (blinking) {
      blinkState = true;
      blinkTimer.begin();
    } else {
      digitalWrite(ledPin, HIGH);
    }
  }
  void update() override { // Called continuously in loop
    if (blinkTimer && blinking) {
      blinkState = !blinkState;
      digitalWrite(ledPin, blinkState ? HIGH : LOW);
    }
  }
  void reset() override { // Called when MIDI Reset All Controllers received
    blinking = false;
    digitalWrite(ledPin, HIGH);
  }

 private:
  pin_t ledPin;
  Timer<millis> blinkTimer;
  bool blinkState = false;
  bool blinking = false;
};

CustomCCLED led {
  13,                      // pin
  MIDI_CC::Channel_Volume, // address
  333,                     // blink interval
};

void setup() { Control_Surface.begin(); }
void loop() { Control_Surface.loop(); }

See Control Surface: Custom-Note-LED-Input-Element-Callback.ino for more information.

You can also do it in the main loop, using the CCValue class, but it gets messy if you have multiple LEDs:

#include <Control_Surface.h>

USBMIDI_Interface midi;

CCValue ccval {MIDI_CC::Channel_Volume};
const pin_t ledPin = 13;
Timer<millis> blinkTimer = 333;

void setup() {
  Control_Surface.begin();
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
}

bool blinkState = false;
bool blinking = false;

void loop() {
  Control_Surface.loop();
  if (ccval.getDirty()) { // the “dirty” flag is set when the value changed
    blinking = ccval.getValue() > 0;
    if (blinking) {
      blinkState = true;
      blinkTimer.begin();
    } else {
      digitalWrite(ledPin, HIGH);
    }
    ccval.clearDirty(); // clear the “dirty” flag to detect the next change
  }
  if (blinkTimer && blinking) {
    blinkState = !blinkState;
    digitalWrite(ledPin, blinkState ? HIGH : LOW);
  }
}

Thanks, it was just what I was looking for, it's perfect. With your bookstore it is possible to do everything.

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