My code is a bit better now, the map function work perfectly, thanks! I still can't figure out how to interrupt the leds when I receive a note at velocity>1. I've tried many different scheme but nothing works. Maybe it's more a midi than LED problem...Here is a version with a boolean between the two callbacks.
#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;
boolean oklight = true;
// 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
digitalWrite(LED,LOW);//Turn LED off
oklight = false;
}
if (velocity > 1) {
oklight = true;
}
}
void HandleControlChange (byte channel, byte number, byte value){
while (oklight == true) {
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
}
Someone inspired?