well I though I could find a way to have one instance of the builtin function in the loop() and sending paramaters from the callbacks but that doesn't work or I'm doing it wrong. I've change the fade time to "instantaneous" so these functions returns quite fast, maybe a wait(1) could be the solution.
here is the code of the fadetohsb function
// Fades to an HSB color
static void BlinkM_fadeToHSB(byte addr, byte hue, byte saturation, byte brightness)
{
Wire.beginTransmission(addr);
Wire.write('h');
Wire.write(hue);
Wire.write(saturation);
Wire.write(brightness);
Wire.endTransmission();
}
.
I suppose the problem appears when I open two connection on the wire. But strangely this code where the led changes are only from midi control change callback works :
#include "Wire.h"
#include "BlinkM_funcs.h"
#include <MIDI.h> // Add Midi Library
#define LED 13 // Arduino Board LED is on Pin 13
byte blinkm_addr = 0x09; // addresse du master controle
int color = 0;
int intensite = 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 = Zero is actualy a NOTE OFF
//BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
}
if (velocity > 1) {
//color = map(velocity, 1, 127, 0, 255);
}
}
void HandleControlChange (byte channel, byte number, byte value){
if (number == 7 ){
intensite = map(value, 0, 127,0, 255);
BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
}
if (number == 14 ){
saturation = map(value, 0, 127,0, 255);
BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
}
if (number == 13 ){
color = map(value, 0, 127, 0, 255);
BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
}
}
void setup() {
BlinkM_begin();
BlinkM_stopScript(blinkm_addr);
BlinkM_fadeToHSB(blinkm_addr, 43, 0, 255);
BlinkM_setFadeSpeed(blinkm_addr,255);
pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to channel 2 notes only.
MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
// tells the Midi Library which function I want called when a Note ON command
// is received. in this case it's "MyHandleNoteOn".
MIDI.setHandleControlChange (HandleControlChange);
}
void loop() { // Main loop
MIDI.read(); // Continually check what Midi Commands have been received
}