Hi,
I am new to Teensy and not the best at writing code.
My goal is to use Midi Control Change info to control multiple LEDs (ultimately 14). I altered some example code and stuff I found on the forum to come up with the code I have now, for 2 LEDs and it works fine, but I am wondering if there is a better way to write this out. Also if the way I have it is the fastest way to transmit the messages over midi to control the LEDs. I want this to be as accurate as possible as I will be syncing this to audio midi messages in the end.
Let me know what you think. Thank you.
I am new to Teensy and not the best at writing code.
My goal is to use Midi Control Change info to control multiple LEDs (ultimately 14). I altered some example code and stuff I found on the forum to come up with the code I have now, for 2 LEDs and it works fine, but I am wondering if there is a better way to write this out. Also if the way I have it is the fastest way to transmit the messages over midi to control the LEDs. I want this to be as accurate as possible as I will be syncing this to audio midi messages in the end.
Let me know what you think. Thank you.
Code:
const int MIDIchannel = 2; // this will only apply to midi channel 2
const int ledPin0 = 0; // digital pin 0
const int ledPin1 = 1; // digital pin 1
const int ledcontroller15 = 15; // midi control change 15
const int ledcontroller16 = 16; // midi control change 16
void setup() {
pinMode(ledPin0, OUTPUT);
pinMode(ledPin1, OUTPUT);
usbMIDI.setHandleControlChange(myControlChange);
// digitalWrite(ledPin, HIGH);
// digitalWrite(ledPin, LOW);
}
void loop() {
usbMIDI.read(MIDIchannel);
}
void myControlChange(byte channel, byte control, byte value) {
if (channel == MIDIchannel
&& control == ledcontroller15
&& value == 0)
digitalWrite(ledPin0, LOW);
if (channel == MIDIchannel
&& control == ledcontroller15
&& value == 127)
digitalWrite(ledPin0, HIGH); // note: short leg of LED connected to ground, long leg to digital pin
if (channel == MIDIchannel
&& control == ledcontroller16
&& value == 0)
digitalWrite(ledPin1, LOW);
if (channel == MIDIchannel
&& control == ledcontroller16
&& value == 127)
digitalWrite(ledPin1, HIGH);
}