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.
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 ¬eInput, 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
};
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.
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");
}
struct MyCallback final : SimpleNoteCCValueCallback {
// Function is called when note event for given range of notes is received.
void update(const INoteCCValue ¬eInput, 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.
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).