Im trying to combine my code with led function

#include <USBAPI.h>
#include <Keypad.h>
#include "FastLED.h"
 
#define MIDI_LED LED_BUILTIN
 
MIDI_CREATE_DEFAULT_INSTANCE();
FASTLED_USING_NAMESPACE
 
#define DATA_PIN    3
#define LED_TYPE    WS2813
#define COLOR_ORDER GRB
#define NUM_LEDS    51
#define HUE_OFFSET  90
 
CRGB leds[NUM_LEDS];
#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120
 
uint8_t gHue = 0;
uint8_t rainbowPos[NUM_LEDS] = { 0 };
uint8_t rainbowDivision = 255 / NUM_LEDS;
 
const byte ROWS = 8;
const byte COLS = 8;
 
char keys[ROWS][COLS] = {
  { 36, 37, 38, 39, 40, 41, 42, 43 },
  { 44, 45, 46, 47, 48, 49, 50, 51 },
  { 52, 53, 54, 55, 56, 57, 58, 59 },
  { 60, 61, 62, 63, 64, 65, 66, 67 },
  { 68, 69, 70, 71, 72, 73, 74, 75 },
  { 76, 77, 78, 79, 80, 81, 82, 83 },
  { 84, 85, 86, 87, 88, 89, 90, 91 },
  { 92, 93, 94, 95, 96, 97, 98, 99 },
};
 
byte rowPins[ROWS] = { 3, 4, 5, 6, 7, 8, 9, 10, };
byte colPins[COLS] = { 11, 12, 13, A0, A1, A2, A3, A4 };
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
 
bool isNoteRecorded[LIST_MAX] = { false };
 
void setup() {
  Serial.begin(31250);
 
  MIDI.begin(MIDI_CHANNEL_OFF);
 
  pinMode(MIDI_LED, OUTPUT);
 
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
 
  for (int i = 0; i < NUM_LEDS; i++) {
    rainbowPos[i] = (gHue + HUE_OFFSET) % 255;
    gHue += rainbowDivision;
  }
}
 
void loop() {
  kpd.getKeys();
 
  for (int i = 0; i < LIST_MAX; i++) {
    if (kpd.key[i].stateChanged) {
      switch (kpd.key[i].kstate) {
        case PRESSED:
          if (!isNoteRecorded[i]) {
            digitalWrite(MIDI_LED, HIGH);
            MIDI.sendNoteOn(kpd.key[i].kchar, 127, 1);
            isNoteRecorded[i] = true;
          }
          break;
        case RELEASED:
          digitalWrite(MIDI_LED, LOW);
          MIDI.sendNoteOff(kpd.key[i].kchar, 0, 1);
          isNoteRecorded[i] = false;
          break;
        case IDLE:
        case HOLD:
          // Ignore these states
          break;
        default:
          // Handle any other unhandled cases if necessary
          break;
      }
    }
  }
 
  MIDI.read();
 
  FastLED.show();
  FastLED.delay(1000 / FRAMES_PER_SECOND);
}
 
void handleNoteOn(byte channel, byte number, byte value) {
  int note = number - 21;
  note *= 2;
 
  switch (channel) {
    case 1:
      leds[note].setHSV(rainbowPos[note], 255, map(value, 0, 127, 100, 255));
      leds[note + 1].setHSV(rainbowPos[note + 1], 255, map(value,  0, 127, 100, 255));
      break;
    // Handle other MIDI channels and corresponding actions here
  }
}
 
void handleNoteOff(byte channel, byte number, byte value) {
  int note = number - 21;
  note *= 2;
 
  leds[note] = CRGB::Black;
  leds[note + 1] = CRGB::Black;
}

so the code compiles but with the added led function, it stops showing up as a midi device ( i assumed id get thrown into "leds" category but put me in my place if not)

remove

replace with

     case 1:
      leds[note].setHSV(rainbowPos[note], 255, map(value, 0, 127, 100, 255));
      leds[note + 1].setHSV(rainbowPos[note + 1], 255, map(value,  0, 127, 100, 255));
      FastLED.show();
      break; 

and this too

 leds[note + 1] = CRGB::Black; FastLED.show();

can you explain this one

add FastLED.show(); after leds[note + 1] = CRGB::Black;

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