How to control Infra-red LED by MIDI ?

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.

You could use something like this:

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

[color=#5e6d03]#include[/color] [color=#434f54]<[/color][b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#000000]h[/color][color=#434f54]>[/color]

[b][color=#d35400]USBMIDI_Interface[/color][/b] [color=#00979c]midi[/color][color=#000000];[/color] [color=#434f54]// MIDI Interface to use[/color]

[color=#00979c]void[/color] [color=#000000]sendIR[/color][color=#000000]([/color][color=#00979c]uint32_t[/color] [color=#000000]cmd[/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Serial[/color][/b] [color=#434f54]<<[/color] [color=#005c5f]"Send IR 0x"[/color] [color=#434f54]<<[/color] [color=#000000]hex[/color] [color=#434f54]<<[/color] [color=#000000]cmd[/color] [color=#434f54]<<[/color] [color=#000000]dec[/color] [color=#434f54]<<[/color] [color=#000000]endl[/color][color=#000000];[/color]
  [color=#434f54]// Implement this[/color]
[color=#000000]}[/color]

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

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

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Serial[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000]115200[/color][color=#000000])[/color][color=#000000];[/color]
  [b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

Pieter

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.

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.

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!!

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:

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Serial[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000]115200[/color][color=#000000])[/color][color=#000000];[/color]
  [b][color=#d35400]Serial[/color][/b][color=#434f54].[/color][color=#d35400]println[/color][color=#000000]([/color][color=#005c5f]"A first line"[/color][color=#000000])[/color][color=#000000];[/color]
  [b][color=#d35400]Serial[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000]115200[/color][color=#000000])[/color][color=#000000];[/color]
  [color=#d35400]delay[/color][color=#000000]([/color][color=#000000]2000[/color][color=#000000])[/color][color=#000000];[/color]
  [b][color=#d35400]Serial[/color][/b][color=#434f54].[/color][color=#d35400]println[/color][color=#000000]([/color][color=#005c5f]"Another line"[/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color][color=#000000]}[/color]

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).

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!