Go Down

Topic: How to control Infra-red LED by MIDI ? (Read 1 time) previous topic - next topic

eulalie_w

I'm looking for the way to operate the infrared LED on Max for live.

I want to emit infrared light (0xFFE01F , 32bit) when I press the midi key number 0.
identically emitting light (0xFF609F , 32bit) when I press the midi key number 1.

I have an Arduino uno and Ableton 10 suite.

Please tell me any ideas.

PieterP

You could use something like this:

https://tttapa.github.io/Control-Surface-doc/Doxygen/dc/d3b/MIDI-Note-Callback-IR_8ino-example.html

#include <Control_Surface.h>

USBMIDI_Interface midi; // MIDI Interface to use

void sendIR(uint32_t cmd) {
  Serial << "Send IR 0x" << hex << cmd << dec << endl;
  // Implement this
}

struct MyCallback final : SimpleNoteCCValueCallback {
  // Function is called when note event for given range of notes is received.
  void update(const INoteCCValue &noteInput, uint8_t index) override {
    if (noteInput.getValue(index) == 0) // check that velocity > 0
      return;
    switch (index) { // index in the range of notes
      case 0: sendIR(0xFFE01F); break;
      case 1: sendIR(0xFF609F); break;
    }
  }
};

// Listen to a range of 2 notes, and use MyCallback.
GenericNoteRange<2, MyCallback> noteInput = {
  0,            // first note number
  MyCallback(), // callback to use
};

void setup() {
  Serial.begin(115200);
  Control_Surface.begin();
}

void loop() {
  Control_Surface.loop();
}
Pieter

eulalie_w

#2
Feb 27, 2020, 11:51 am Last Edit: Feb 27, 2020, 11:59 am by eulalie_w
Thank you so much!!!!
I'm really beginner .
Your answer help me a lot. I connected Arduino to my Ableton and it seems so good.


I want to choice a pin for IR.
I tried to write in addition to yours however it didn't move.

Would it be okay if I asked you to help me?



#include <Control_Surface.h>

USBMIDI_Interface midi; // MIDI Interface to use
int led = 3 ;

void sendIR(uint32_t cmd) {
  Serial << "Send IR 0x" << hex << cmd << dec << endl;
  // Implement this
}

struct MyCallback final : SimpleNoteCCValueCallback {
  // Function is called when note event for given range of notes is received.
  void update(const INoteCCValue &noteInput, uint8_t index) override {
    if (noteInput.getValue(index) == 0) // check that velocity > 0
      return;
    switch (index) { // index in the range of notes
      case 0: sendIR(0xFFE01F); break;
      case 1: sendIR(0xFF609F); break;
    }
  }
};

// Listen to a range of 2 notes, and use MyCallback.
GenericNoteRange<2, MyCallback> noteInput = {
  0,            // first note number
  MyCallback(), // callback to use
};

void setup() {
  Serial.begin(115200);
  Control_Surface.begin();
  pinMode(led,OUTPUT);
}

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


Cheers.

PieterP

You cannot change the IR pin because of hardware constraints. It has to be a specific pin connected to a specific timer. You can change it to some different timer pin.

See this.

eulalie_w

I'm still having problems getting this to work. I am trying to bridge from AbletonLive with HairlessMIDI so I changed your recommended code a little bit

#include <Control_Surface.h>

HairlessMIDI_Interface midi;

void sendIR(uint32_t cmd) {
  Serial << "Send IR 0x" << hex << cmd << dec << endl;
  // Implement this
  Serial.print("sendIR");
}

void setup()
{
  Serial.begin(115200);
  Serial.print("setup");
  Control_Surface.begin();
}

struct MyCallback final : SimpleNoteCCValueCallback {
  // Function is called when note event for given range of notes is received.
  void update(const INoteCCValue &noteInput, uint8_t index) override {
    Serial.print("MyCallback");
  }
};
 
// Listen to a range of 2 notes, and use MyCallback.
GenericNoteRange<2, MyCallback> noteInput = {
  0,            // first note number
  MyCallback(), // callback to use
};

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


I expect to see "MyCallback" print to the serial monitor on playing the events in Ableton. I can see them enter Hairless correctly (although they say "SystemMessage #8") and I've set up all baud rates to 115200. But what I get is "se" come through the monitor... It's like everything freezes on Control_Surface.begin();... Any advice would be appreciated!!

PieterP

#5
Mar 14, 2020, 04:11 pm Last Edit: Mar 14, 2020, 04:13 pm by PieterP
The problem is that you are calling Serial.print() before Control_Surface.begin().

Control_Surface.begin() will initialize the HairlessMIDI_Interface, which will in turn call Serial.begin() again. Calling Serial.begin() multiple times is not an issue, but if you've previously added data to the buffer, this can corrupt it.

Simple example to reproduce:
void setup() {
  Serial.begin(115200);
  Serial.println("A first line");
  Serial.begin(115200);
  delay(2000);
  Serial.println("Another line");
}

void loop() {}
The solution: Either print after Control_Surface.begin(), or if you need to print before it, call Serial.flush() right before Control_Surface.begin.

The reason you're not seeing MyCallback printed is because you're not getting the right messages. The callback will only fire when note messages for notes 0 and 1 are received on MIDI channel 1, the code I posted doesn't react to "SystemMessage #8".

I've just tried the original sketch I posted in reply #1, and it works correctly if I send note events like "90 00 7F" (note on #0, channel 1, velocity 0x7F) and "90 01 10" (note on #1, channel 1, velocity 0x10).

eulalie_w

Hi PieterP !!!!
Thank you so much for your help !!!!

Arduino works as expected.
If not for your help, I would not have been completed this work.
I really appreciate you.


This is a production's video.
https://twitter.com/eeulaliee/status/1242381779551449088?s=20

Thank you for your kindness.
Cheers!

Go Up