sargentpilcher
Well-known member
Hello all,
I have a set of LED strips that I am using MIDI to trigger the lights to come off and on. I am for the most part very pleased with the setup and how everything works, but there is a feature I'm trying to add that I can't get to work. In my code I have it written so that the velocity controls the brightness value, and it works great. However, I want to be able to fade the lights in and out, and I'm attempting to make it so that the Pitch Bend wheel will control how bright all the LED's become. In my code it's written like
colorMatrix[light][note%3] = velocity+usbMIDI.PitchBend;
But it doesn't work. It works GREAT if I put
colorMatrix[light][note%3] = velocity*2;
Putting "usbMIDI.PitchBend" into the function makes it not respond to velocity and brightness at all. It "breaks" the code completely even having it in there (No errors or anything, it just doesn't DO anything.) Is there an alternate variable or call function I should use?
Is the amount of MIDI related commands limited to what exists on this page: https://www.pjrc.com/teensy/td_midi.html
Because I don't see anything involving a Mod wheel command on that page, but I would love to be able to use my Mod wheel with the Teensy.
I have a set of LED strips that I am using MIDI to trigger the lights to come off and on. I am for the most part very pleased with the setup and how everything works, but there is a feature I'm trying to add that I can't get to work. In my code I have it written so that the velocity controls the brightness value, and it works great. However, I want to be able to fade the lights in and out, and I'm attempting to make it so that the Pitch Bend wheel will control how bright all the LED's become. In my code it's written like
colorMatrix[light][note%3] = velocity+usbMIDI.PitchBend;
But it doesn't work. It works GREAT if I put
colorMatrix[light][note%3] = velocity*2;
Putting "usbMIDI.PitchBend" into the function makes it not respond to velocity and brightness at all. It "breaks" the code completely even having it in there (No errors or anything, it just doesn't DO anything.) Is there an alternate variable or call function I should use?
Is the amount of MIDI related commands limited to what exists on this page: https://www.pjrc.com/teensy/td_midi.html
Because I don't see anything involving a Mod wheel command on that page, but I would love to be able to use my Mod wheel with the Teensy.
Code:
#include <Adafruit_DotStar.h>
#define NUMPIXELS 240 //Dotstar pixels
#define DATAPIN 36
#define CLOCKPIN 35
byte colorMatrix[16*42][3] ; // 2D matrix to hold velocity readings - index is for light number
unsigned int light; // light is cacluatated by multiplying zero-indexed channel ID * 42 lights per channel + integer trunc of note/3
Adafruit_DotStar strip1 = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG); // initialize pixel object
void setup(){
usbMIDI.setHandleNoteOn(OnNoteOn);
usbMIDI.setHandleNoteOff(OnNoteOff);
strip1.begin();
strip1.show(); // Initialize all pixels to 'off'
}
void OnNoteOn(byte channel, byte note, byte velocity){
light = (channel*42)-(42) + note/3; // calculate which light the message is for
// note%3 returns an index for the three RGB positions 0,1,2 based on the remainder when the note is divided by three!
colorMatrix[light][note%3] = velocity*usbMIDI.PitchBend; // read the velocity and scale to 8-bit from 7 and write to matrix
// could make set pixel conditional to blue updates (if (note%3 = 2)...) if you make sure all three are sent in order when a light's values are changed
// this wouild prevent updates before all values are available to avoid incorrect colors being displayed wiht R and G valeues being sent
strip1.setPixelColor(light,colorMatrix[light][0],colorMatrix[light][1],colorMatrix[light][2]);
}
void OnNoteOff(byte channel, byte note, byte velocity){
light = (channel*42)-(42) + note/3; // calculate which light the message is for
// note%3 returns an index for the three RGB positions 0,1,2 based on the remainder when the note is divided by three!
colorMatrix[light][note%3] = 0; // read the velocity and scale to 8-bit from 7 and write to matrix
// could make set pixel conditional to blue updates (if (note%3 = 2)...) if you make sure all three are sent in order when a light's values are changed
// this wouild prevent updates before all values are available to avoid incorrect colors being displayed wiht R and G valeues being sent
strip1.setPixelColor(light,colorMatrix[light][0],colorMatrix[light][1],colorMatrix[light][2]);
}
void loop() {
while (usbMIDI.read()) {
// keep reading until all incoming messages read
}
strip1.show();
}