Midiusb VUMETER

after i solve the problem with the noteon and noteoff is time for the vumeter.

what i want to do is, if the arduino receive cc21 and value 0. no led to light.
if value is 1, then 1 led to light. if value is 2 then second led to lit, and so on.
if value is 5 all the leds to come on. if alue drop to 4, then led no5 mast turn off or if value drop to 2 leds should turn off till led no2.

i try the code below, but i only manage to turn the led up when the value encrease from 0-5, but leds never come off. i know this is not the correct way do it. so please any help to move on would be fine.. THANK U

#include "MIDIUSB.h"// Library from here https://github.com/FortySevenEffects/arduino_midi_library
#include "LedControl.h"

//pin 12 is connected to the DataIn
// pin 11 is connected to the CLK
// pin 10 is connected to LOAD
LedControl lc = LedControl(12, 11, 10, 1);

void setup() {

  lc.shutdown(0, false);

  lc.setIntensity(0, 8);

  lc.clearDisplay(0);

  Serial.begin(115200);
  lc.setLed (0, 1, 1, true); // turn 1 led on to see if the code is working
}

void loop() {
  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();


    if (rx.header == 0xB) vumeter(rx.byte1, rx.byte2, rx.byte3);
  }
  while (rx.header == 0); // hold until a MIDI message is received
}

void vumeter(byte channel, byte control, byte value) {

  switch (value) {
    case 1:

      if (value == 1 ) {

        lc.setLed(0, 2, 1, true);
      }
      else if (value == 0 ) {
        lc.setLed(0, 2, 1, false);
      }
      break;

    case 2:
      if (value == 2 ) {

        lc.setLed(0, 2, 2, true);
      }
      else if (value == 0 ) {
        lc.setLed(0, 2, 2, false);
      }
      break;


    case 3:
      if (value == 3 ) {

        lc.setLed(0, 2, 3, true);
      }
      else if (value == 0 ) {
        lc.setLed(0, 2, 3, false);
      }
      break;

    case 4:
      if (value == 4 ) {

        lc.setLed(0, 2, 4, true);
      }
      else if (value == 0 ) {
        lc.setLed(0, 2, 4, false);
      }
      break;

    case 5:
      if (value == 5 ) {

        lc.setLed(0, 2, 5, true);
      }
      else if (value == 0 ) {
        lc.setLed(0, 2, 5, false);
      }
      break;

  }

}



void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}


void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);

}

void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

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