4 Neopixels strip controlled by MIDI

Hi all

I'm French & new to Arduino. I need some help to use 4 NeoPixels strip controlled by MIDI. I would use them as a Vumeter. I have this code

int velocity;

#include <MIDIUSB.h>
#include "pitchToFrequency.h"
//#include <FastLED.h>
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN        6 // pin sortie deck A
#define PIN1       7 // pin sortie deck B 
#define PIN2       8 // pin sortie deck C
#define PIN3       9 // pin sortie deck D

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS   8 // Popular NeoPixel strip Deck A
#define NUMPIXELS1  8 // Popular NeoPixel strip deck B
#define NUMPIXELS2  8 // Popular NeoPixel strip deck C
#define NUMPIXELS3  8 // Popular NeoPixel strip deck D

// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 32

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);

uint32_t offColor = strip.Color(0, 0, 0);  // Strip off
uint32_t whiteColor = strip.Color(32, 32, 32);
uint32_t yellowColor = strip.Color(127, 64, 0);
uint32_t redColor = strip.Color(64, 0, 0);
uint32_t blueColor = strip.Color(0, 0, 64);

#define BUZZ_PIN 9 // pin sortie buzzer 

byte ng;
byte oct;
const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}

int pitch_octave(byte pitch) {
  return (pitch / 12) - 1;
}

void noteOn(byte channel, byte pitch, byte velocity) {
  tone(BUZZ_PIN, pitchFrequency[pitch]);

  Serial.print("Note On: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.print(velocity);
  ng  = pitch % 12;
  oct = pitch / 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  strip.setPixelColor(ng, 0, 150, 0);
  strip.show();

}

void noteOff(byte channel, byte pitch, byte velocity) {
  noTone(BUZZ_PIN);

  Serial.print("Note Off: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.println(velocity);

  ng  = pitch % 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  strip.setPixelColor(ng, 0, 0, 0);
  strip.show();



}

void controlChange(byte channel, byte control, byte value) {
  Serial.print("Control change: control=");
  Serial.print(control);
  Serial.print(", value=");
  Serial.print(value);
  Serial.print(", channel=");
  Serial.println(channel);
}

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.clear();
}

void loop() {


  noPixels();
  midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events

    case 0x9:
      noteOn(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity


      );
      velocity = rx.byte3;
      break;

    case 0x8:
      noteOff(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity

      );
      velocity = 0;
      break;

    case 0xB:
      controlChange(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //control
        rx.byte3         //value
      );
      break;

    default:
      Serial.print("Unhandled MIDI message: ");
      Serial.print(rx.header, HEX);
      Serial.print("-");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, HEX);
      Serial.print("-");
      Serial.println(rx.byte3, HEX);
  }



  //strip.noPixels();
  if (velocity < 1) {
    //    pixels.setPixelColor(0, greenColor);
    strip.setPixelColor(0, offColor);
  }
  if (velocity > 30) {
    //    pixels.setPixelColor(0, greenColor);
    strip.setPixelColor(0, whiteColor);
  }
  if (velocity > 50) {
    //    pixels.setPixelColor(1, greenColor);
    strip.setPixelColor(1, whiteColor);
  }
  if (velocity > 75) {
    //    pixels.setPixelColor(2, greenColor);
    strip.setPixelColor(2, whiteColor);
  }
  if (velocity > 80) {
    //    pixels.setPixelColor(3, yellowColor);
    strip.setPixelColor(3, whiteColor);
  }
  if (velocity > 90) {
    //    pixels.setPixelColor(4, yellowColor);
    strip.setPixelColor(4, whiteColor);
  }
  if (velocity > 110 ) {
    //    pixels.setPixelColor(5, yellowColor);
    strip.setPixelColor(5, blueColor);
  }
  if (velocity > 120) {
    strip.setPixelColor(6, blueColor);
  }
  if (velocity > 126) {
    strip.setPixelColor(7, redColor);

  }

  strip.show();

}




void noPixels()
{
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, offColor);
  }
  strip.show();
}

It works well but no matter which note is played, the strip always react. I would like to route MIDI channel 16 note A0 to Pin 6 only, note B0 ton PIN 7 only, note C0 to PIN 8 only & note D0 to PIN 9 only.
I defined the 4 strips, but I don't know how to route each MIDI note to the respective strip.

Can you help me ?

Thanks

You are always updating strip, never strip1, strip2 etc.

My first question, upon reading your post, was why did you connect the strips to 4 different pins, instead of just one pin?

Connecting separate strips to different pins can be useful in some circumstances, but I don't think this is one of them.

It might be easier to connect your strips as a chain and use only one arduino pin, if it's not too late to change that.

If it is too late, I suggest you make an array of strips, so

Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);

becomes

Adafruit_NeoPixel strip[4] = {
  Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800)
};

(the first of a few changes, just to get you started).

Sorry I misspoke.

I begun to define 4 strips because it's my goal. 4 different strip to 4 different PIN to use as a vumeter. 1 strip for each deck of Traktor. For the moment, as I'm a noob, I practice with 1 strip on PIN 6 . But it doesn't work as I want. It reacts to all midi note no matter midi channel I choose.

Here is my goal :

I want Strip on PIN 6 react to note A0 channel 16 ONLY.
I want Strip1 on PIN 7 react to note B0 channel 16 ONLY
I want Strip2 on PIN 8 react to note C0 channel 16 ONLY
I want Strip3 on PIN 9 react to note D0 channel 16 ONLY

So that means you have to test for that before you do anything with the result.
Take @PaulRB advice and create the array.

    case 0x9:
      noteOn(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity


      );
      pitch = rx.byte2;
      velocity = rx.byte3;
      break;

    case 0x8:
      noteOff(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity

      );
      velocity = 0;
      break;

and add

int pitch;

then you can compare

if (pitch == thePitchYouWant) { etc.

I understand that it is your goal to have 4 strips. My question is why you are using 4 pins? All 4 strips can be connected, in a chain, to 1 pin. This would be easier.

Ok so if I chain 4 NeoPixel I need to define only PIN 6 & NUMPIXELS to 32. is it right?

now I tried to do that :

if ((rx.byte1 == 15) && (rx.byte2 == 21) && (velocity > 30)) {
//    pixels.setPixelColor(0, greenColor);
    strip.setPixelColor(0, whiteColor);
}

& son on... but it doesn't work :frowning:

Well how about you first restructure your sketch.

Yes that is correct. Or you can go for the method of creating an array of strips.
Then you should determine which strip (or section of strip) you want to address, by comparing the pitch of the note you have received. But i do suggest this modification that also turns the pixel 'off' when velocity is too low.

//strip.noPixels();
  if (velocity < 1) {
    //    pixels.setPixelColor(0, greenColor);
    strip.setPixelColor(0, offColor);
  }
  if (velocity > 30) {
    //    pixels.setPixelColor(0, greenColor);
    strip.setPixelColor(0, whiteColor);
  }
  if (velocity > 50) {
    //    pixels.setPixelColor(1, greenColor);
    strip.setPixelColor(1, whiteColor);
  }
  else {
     strip.setPixelColor(1, offColor);
  }
  if (velocity > 75) {
    //    pixels.setPixelColor(2, greenColor);
    strip.setPixelColor(2, whiteColor);
  }
 else {
     strip.setPixelColor(2, offColor);
  }
  if (velocity > 80) {
    //    pixels.setPixelColor(3, yellowColor);
    strip.setPixelColor(3, whiteColor);
  }
 else {
     strip.setPixelColor(3, offColor);
  }
  if (velocity > 90) {
    //    pixels.setPixelColor(4, yellowColor);
    strip.setPixelColor(4, whiteColor);
  }
 else {
     strip.setPixelColor(4, offColor);
  }
  if (velocity > 110 ) {
    //    pixels.setPixelColor(5, yellowColor);
    strip.setPixelColor(5, blueColor);
  }
  else {
     strip.setPixelColor(5, offColor);
  }
  if (velocity > 120) {
    strip.setPixelColor(6, blueColor);
  }
 else {
     strip.setPixelColor(6, offColor);
  }
  if (velocity > 126) {
    strip.setPixelColor(7, redColor);
  }
 else {
     strip.setPixelColor(7, offColor);
  }
  strip.show();

I suppose you could also clear the whole strip before.
Anyway you will need to reference 'strip' to whichever strip you want to address (i said that already didn't i)

Also please post your whole new sketch (nearly) every time you make adjustments because :

That line does not explain what you've changed and where and how you have (obviously) made what mistake etc. So that does not help us in helping you.
Do not despair, we will manage.

Done.

and add

int pitch;

at the beginning of the sketch (Line 2) right?

I would like the simplest LOL.

where I have to write this part?

I've also opened a topic in a French forum, someone said that :

You have to delete all the velocity test in "loop" section & put them in NoteOn, combined to ng value & octave.
currently, you call NoteOn fonction, but you erase all by doing velocity test in loop section. you have to do them all in one place, with combination of (&&).

what do you think about that?

here is sketch updated :

int velocity;
int pitch;

#include <MIDIUSB.h>
#include "pitchToFrequency.h"
//#include <FastLED.h>
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN        6 // pin strip

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS   32 // Popular NeoPixel

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


uint32_t offColor = strip.Color(0, 0, 0);  // Strip off
uint32_t whiteColor = strip.Color(255, 255, 255);
uint32_t yellowColor = strip.Color(127, 64, 0);
uint32_t redColor = strip.Color(255, 0, 0);
uint32_t blueColor = strip.Color(0, 0, 255);

#define BUZZ_PIN 9 // pin sortie buzzer 

byte ng;
byte oct;
const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}

int pitch_octave(byte pitch) {
  return (pitch / 12) - 1;
}

void noteOn(byte channel, byte pitch, byte velocity) {
  tone(BUZZ_PIN, pitchFrequency[pitch]);

  Serial.print("Note On: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.print(velocity);
  ng  = pitch % 12;
  oct = pitch / 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  strip.setPixelColor(ng, 0, 150, 0);
  strip.show();

}

void noteOff(byte channel, byte pitch, byte velocity) {
  noTone(BUZZ_PIN);

  Serial.print("Note Off: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.println(velocity);

  ng  = pitch % 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  strip.setPixelColor(ng, 0, 0, 0);
  strip.show();



}

void controlChange(byte channel, byte control, byte value) {
  Serial.print("Control change: control=");
  Serial.print(control);
  Serial.print(", value=");
  Serial.print(value);
  Serial.print(", channel=");
  Serial.println(channel);
}

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.clear();
}

void loop() {


  noPixels();
  midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events

    case 0x9:
      noteOn(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity


      );
      pitch = rx.byte2;
      velocity = rx.byte3;
      
      break;

    case 0x8:
      noteOff(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity

      );
      velocity = 0;
      break;


    case 0xB:
      controlChange(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //control
        rx.byte3         //value
      );
      break;


    default:
      Serial.print("Unhandled MIDI message: ");
      Serial.print(rx.header, HEX);
      Serial.print("-");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, HEX);
      Serial.print("-");
      Serial.println(rx.byte3, HEX);
  }



  //strip.noPixels();
  if (velocity > 50) {
    //    pixels.setPixelColor(0, whiteColor);
    strip.setPixelColor(0, whiteColor);
  }
  else {
     strip.setPixelColor(0, offColor);
  }
  if (velocity > 65) {
    //    pixels.setPixelColor(1, whiteColor);
    strip.setPixelColor(1, whiteColor);
  }
  else {
     strip.setPixelColor(1, offColor);
  }
  if (velocity > 80) {
    //    pixels.setPixelColor(2, whiteColor);
    strip.setPixelColor(2, whiteColor);
  }
 else {
     strip.setPixelColor(2, offColor);
  }
  if (velocity > 95) {
    //    pixels.setPixelColor(3, whiteColor);
    strip.setPixelColor(3, whiteColor);
  }
 else {
     strip.setPixelColor(3, offColor);
  }
  if (velocity > 100) {
    //    pixels.setPixelColor(4, whiteColor);
    strip.setPixelColor(4, whiteColor);
  }
 else {
     strip.setPixelColor(4, offColor);
  }
  if (velocity > 110 ) {
    //    pixels.setPixelColor(5, blueColor);
    strip.setPixelColor(5, blueColor);
  }
  else {
     strip.setPixelColor(5, offColor);
  }
  if (velocity > 120) {
    //    pixels.setPixelColor(6, blueColor);
    strip.setPixelColor(6, blueColor);
  }
 else {
     strip.setPixelColor(6, offColor);
  }
  if (velocity > 126) {
    //    pixels.setPixelColor(7, redColor);
    strip.setPixelColor(7, redColor);
  }
 else {
     strip.setPixelColor(7, offColor);
  }
  strip.show();

}




void noPixels()
{
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, offColor);
  }
  strip.show();
}

Yep, or anywhere before setup(). I group my global declarations as follows, but usually any order is fine, though objects rarely should be declared before included files of course.

  • #include
  • #define
  • constants
  • objects
  • variables

The simplest is to make a choice and stick with it. You have done so now. All on 1 pin it is !

I have now opened your sketch in the IDE and i will clean it up a tad and modify a few things.

#include <MIDIUSB.h>
//#include "pitchToFrequency.h"
#include <Adafruit_NeoPixel.h>

#define PIN        6 // pin strip
#define BUZZ_PIN 9 // pin sortie buzzer
#define NUMPIXELS   32 // Popular NeoPixel

Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int velocity;
int pitch;

uint32_t offColor = strip.Color(0, 0, 0);  // Strip off
uint32_t whiteColor = strip.Color(255, 255, 255);
uint32_t yellowColor = strip.Color(127, 64, 0);
uint32_t redColor = strip.Color(255, 0, 0);
uint32_t blueColor = strip.Color(0, 0, 255); 

byte ng;
byte oct;

const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}

int pitch_octave(byte pitch) {
  return (pitch / 12) - 1;
}

void noteOn(byte channel, byte pitch, byte velocity) {
  //tone(BUZZ_PIN, pitchFrequency[pitch]);

  Serial.print("Note On: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.print(velocity);
  ng  = pitch % 12;
  oct = pitch / 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  //strip.setPixelColor(ng, 0, 150, 0);
  //strip.show();
}

void noteOff(byte channel, byte pitch, byte velocity) {
  noTone(BUZZ_PIN);

  Serial.print("Note Off: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.println(velocity);

  ng  = pitch % 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  //strip.setPixelColor(ng, 0, 0, 0);
  //strip.show();
}

void controlChange(byte channel, byte control, byte value) {
  Serial.print("Control change: control=");
  Serial.print(control);
  Serial.print(", value=");
  Serial.print(value);
  Serial.print(", channel=");
  Serial.println(channel);
}

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.clear();
}

void loop() {
  midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events
    case 0x9:
      noteOn(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity
      );
      pitch = rx.byte2;
      velocity = rx.byte3;      
      break;
    case 0x8:
      noteOff(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity
      );
      pitch = rx.byte2;
      velocity = 0;
      break;
    case 0xB:
      controlChange(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //control
        rx.byte3         //value
      );
      break;
    default:
      Serial.print("Unhandled MIDI message: ");
      Serial.print(rx.header, HEX);
      Serial.print("-");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, HEX);
      Serial.print("-");
      Serial.println(rx.byte3, HEX);
  }
  showPixels(pitch, velocity);
  
}

void showPixels(byte pitch, byte velocity) {
  const byte Nr_notes = 4;
  const byte notes[Nr_notes] = {33, 35, 36, 38}; // A0, B0, C0, D0
  byte i = Nr_notes;
  byte foundNote = Nr_notes;
  while (i) {
    i--;
    if (pitch == notes[i]) foundNote = i;
  }  // this should pick the proper note
  if (foundNote == Nr_notes) return;  // not a note we want to do something with
  foundNote = foundNote * 8; // creating the proper offset
  clearStripSection(foundNote);
  if (velocity > 50) {
    strip.setPixelColor(0 + foundNote, whiteColor);
  }
  if (velocity > 65) {
    strip.setPixelColor(1 + foundNote, whiteColor);
  }
  if (velocity > 80) {
    strip.setPixelColor(2 + foundNote, whiteColor);
  }
  if (velocity > 95) {
    strip.setPixelColor(3 + foundNote, whiteColor);
  }
  if (velocity > 100) {
    strip.setPixelColor(4 + foundNote, whiteColor);
  }
  if (velocity > 110 ) {
    strip.setPixelColor(5 + foundNote, blueColor);
  }
  if (velocity > 120) {
    strip.setPixelColor(6 + foundNote, blueColor);
  }
  if (velocity > 126) {
    strip.setPixelColor(7 + foundNote, redColor);
  }
  strip.show();
}

void clearStripSection(byte offset) {
  for (int i = offset; i < offset + 8; i++) {
    strip.setPixelColor(i, offColor);
  }
}

/*void noPixels() {
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, offColor);
  }
  strip.show();
}*/ 

(edit i messed up a bit with the while loop, should be correct now !)
I commented a few things out. We don't want the noteOn & noteOff functions to actually use the LEDs it is only going to be confusing.
I don't have you pitch to frequency file, and anyway i found that the tone() function is way to inaccurate for my ears. Not only that, calling show() may interfere with the timer1 interrupt that it uses.
Anyway does this make sense to you ? and more importantly, does it work ?

Finally I've found the issue

Here is my final sketch, working perfect.

int velocity;
int canal;
int pitch;


#include <MIDIUSB.h>
#include "pitchToFrequency.h"
//#include <FastLED.h>
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN        6 // pin strip

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS   32 // Popular NeoPixel

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


uint32_t offColor = strip.Color(0, 0, 0);  // Strip off
uint32_t whiteColor = strip.Color(255, 255, 255);
uint32_t yellowColor = strip.Color(127, 64, 0);
uint32_t redColor = strip.Color(255, 0, 0);
uint32_t blueColor = strip.Color(0, 0, 255);

byte ng;
byte oct;
const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}

int pitch_octave(byte pitch) {
  return (pitch / 12) - 1;
}

void noteOn(byte channel, byte pitch, byte velocity) {

  Serial.print("Note On: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print("pitch=");
  Serial.println(pitch);
  Serial.print(", velocity=");
  Serial.print(velocity);
  ng  = pitch % 12;
  oct = pitch / 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  strip.setPixelColor(ng, 0, 150, 0);
  strip.show();

}

void noteOff(byte channel, byte pitch, byte velocity) {

  Serial.print("Note Off: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print("pitch=");
  Serial.println(pitch);
  Serial.print(", velocity=");
  Serial.println(velocity);

  ng  = pitch % 12;
  Serial.print(", ng= ");
  Serial.println(ng);
  strip.setPixelColor(ng, 0, 0, 0);
  strip.show();



}

void controlChange(byte channel, byte control, byte value) {
  Serial.print("Control change: control=");
  Serial.print(control);
  Serial.print(", value=");
  Serial.print(value);
  Serial.print(", channel=");
  Serial.println(channel);
}

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.clear();
}

void loop() {


  noPixels();
  midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events

    case 0x9:
      noteOn(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity


      );
      canal=rx.byte1 & 0xF;
      pitch=rx.byte2;
      velocity=rx.byte3;
      
      break;

    case 0x8:
      noteOff(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity

      );
      velocity=0;
      pitch=rx.byte2;
      canal=rx.byte1 & 0xF;
      break;


    case 0xB:
      controlChange(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //control
        rx.byte3         //value
      );
      canal=rx.byte1 & 0xF;
      break;


    default:
      Serial.print("Unhandled MIDI message: ");
      Serial.print(rx.header, HEX);
      Serial.print("-");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, HEX);
      Serial.print("-");
      Serial.println(rx.byte3, HEX);
  }



  //strip.noPixels();
  if ((canal == 15) && (pitch == 21) && (velocity > 50)) {
    //    pixels.setPixelColor(0, whiteColor);
    strip.setPixelColor(0, whiteColor);
  }
  else {
     strip.setPixelColor(0, offColor);
  }    
  if ((canal == 15) && (pitch == 21) && (velocity > 65)) {
    //    pixels.setPixelColor(1, whiteColor);
    strip.setPixelColor(1, whiteColor);
  }
  else {
     strip.setPixelColor(1, offColor);
  }
  if ((canal == 15) && (pitch == 21) && (velocity > 80)) {
    //    pixels.setPixelColor(2, whiteColor);
    strip.setPixelColor(2, whiteColor);
  }
 else {
     strip.setPixelColor(2, offColor);
  }
  if ((canal == 15) && (pitch == 21) && (velocity > 95)) {
    //    pixels.setPixelColor(3, whiteColor);
    strip.setPixelColor(3, whiteColor);
  }
 else {
     strip.setPixelColor(3, offColor);
  }
  if ((canal == 15) && (pitch == 21) && (velocity > 100)) {
    //    pixels.setPixelColor(4, whiteColor);
    strip.setPixelColor(4, whiteColor);
  }
 else {
     strip.setPixelColor(4, offColor);
  }
  if ((canal == 15) && (pitch == 21) && (velocity > 110)) {
    //    pixels.setPixelColor(5, blueColor);
    strip.setPixelColor(5, blueColor);
  }
  else {
     strip.setPixelColor(5, offColor);
  }
  if ((canal == 15) && (pitch == 21) && (velocity > 120)) {
    //    pixels.setPixelColor(6, blueColor);
    strip.setPixelColor(6, blueColor);
  }
 else {
     strip.setPixelColor(6, offColor);
  }
  if ((canal == 15) && (pitch == 21) && (velocity > 126)) {
    //    pixels.setPixelColor(7, redColor);
    strip.setPixelColor(7, redColor);
  }
 else {
     strip.setPixelColor(7, offColor);
  }
  strip.show();

}




void noPixels()
{
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, offColor);
  }
  strip.show();
}

I have deleted all line related to buzz, because I don't use any buzzer.

Next step, add the last 3 strip.

That is going to be problematic with the structure you have created, but good luck !

Why?

Your structure should be better?

I think you are breaking the forum rules by cross-posting. Never do that again, or the moderators may ban you from the forum. The different languages used do not make it ok to cross-post.

A post on an other site.

I opened one post on French Arduino Forum but it was for midi controller, not for NeoPixel.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.