Hello,
I need some basic programming advice on my project. I'm driving maxm rgb led modules with midi from ableton live. I want to be able to control the color (hue) with the note intensity value, the saturation with the channel volume control change and the value with the channel control n°14.
For now, when one of this message is received, the BlinkM_fadeToHSB() is called with the changed parameters. The problem is I can't get led's off with the intensity at 1 because the other functions are still called by the other functions fadeToHSB called. How can I manage this better?
Second short question, my midi data values are from 1 to 127 and I would like to transform them from 0 to 255 with artificial +1 increments, is there an elegant way to do that?
Last one, due to the midi specific baud rate, I can't get the serial monitor working to have a look at my variables or midi in messages. Is there a workaround for that?
Thanks to all, here is my code. Maxm is externaly powered, midi in arrives on rx pin.
#include "Wire.h"
#include "BlinkM_funcs.h"
#include <MIDI.h>
#define LED 13
byte blinkm_addr = 0x09;
int color = 0;
int intensity = 255;
int saturation= 255;
// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
digitalWrite(LED,HIGH); //Turn LED on
if (velocity == 1) {//A NOTE ON message with a velocity = 1is actualy a NOTE OFF
digitalWrite(LED,LOW);//Turn LED off
BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
}
color = velocity*2+1;
BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
}
void HandleControlChange (byte channel, byte number, byte value){
if (number == 7){
intensity = value*2+1;
BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
}
if (number == 14){
saturation = value*2+1;
BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
}
void setup() {
BlinkM_begin();
BlinkM_stopScript(blinkm_addr);
BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
BlinkM_setFadeSpeed(blinkm_addr,255);
pinMode (LED, OUTPUT);
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleNoteOn(MyHandleNoteOn);
MIDI.setHandleControlChange (HandleControlChange);
}
void loop() { // Main loop
MIDI.read(); // Continually check what Midi Commands have been received
}