#include <FastLED.h>
#include <vector>
#define NUM_LEDS 256
#define LED_PIN 2
#define NUM_BLOCKS 16
#define LEDS_PER_BLOCK 16
CRGB leds[NUM_LEDS];
int ledBlocks[NUM_BLOCKS][LEDS_PER_BLOCK] = {
{0, 1, 2, 3, 31, 30, 29, 28, 32, 33, 34, 35, 60, 61, 62, 63}, // Block 0,0 - midi notes: 127,126,125 (b,r,g)
{64, 65, 66, 67, 95, 94, 93, 92, 96, 97, 98, 99, 127, 126, 125, 124}, // Block 1,0 - midi notes: 124,123,122 (b,r,g)
{128, 129, 130, 131, 159, 158, 157, 156, 160, 161, 162, 163, 191, 190, 189, 188}, // Block 2,0 - midi notes: 121,120,119 (b,r,g)
{192, 193, 194, 195, 223, 222, 221, 220, 224, 225, 226, 227, 255, 254, 253, 252}, // Block 3,0 - midi notes: 118,117,116 (b,r,g)
{4, 5, 6, 7, 27, 26, 25, 24, 36, 37, 38, 39, 59, 58, 57, 56}, // Block 0,1 - midi notes: 115,114,113
{68, 69, 70, 71, 91, 90, 89, 88, 100, 101, 102, 103, 123, 122, 121, 120}, // Block 1,1 - midi notes: 112,111,110
{132, 133, 134, 135, 155, 154, 153, 152, 164, 165, 166, 167, 187, 186, 185, 184}, // Block 2,1 - midi notes: 109,108,107
{196, 197, 198, 199, 219, 218, 217, 216, 228, 229, 230, 231, 251, 250, 249, 248}, // Block 3,1 - midi notes: 106,105,104
{8, 9, 10, 11, 23, 22, 21, 20, 40, 41, 42, 43, 55, 54, 53, 52}, // Block 0,2 - midi notes: 103,102,101 (b,r,g)
{72, 73, 74, 75, 87, 86, 85, 84, 104, 105, 106, 107, 119, 118, 117, 116}, // Block 1,2 - midi notes: 100,99,98
{136, 137, 138, 139, 151, 150, 149, 148, 168, 169, 170, 171, 183, 182, 181, 180}, // Block 2,2 - midi notes: 97,96,95
{200, 201, 202, 203, 215, 214, 213, 212, 232, 233, 234, 235, 247, 246, 245, 244}, // Block 3,2 . midi notes: 94,93,92
{12, 13, 14, 15, 19, 18, 17, 16, 44, 45, 46, 47, 51, 50, 49, 48}, // Block 0,3 - midi notes: 91,90,89 (b,r,g)
{76, 77, 78, 79, 83, 82, 81, 80, 108, 109, 110, 111, 115, 114, 113, 112}, // Block 1,3 - midi notes: 88,87,86
{140, 141, 142, 143, 147, 146, 145, 144, 172, 173, 174, 175, 179, 178, 177, 176}, // Block 2,3 - midi notes: 85,84,83
{204, 205, 206, 207, 211, 210, 209, 208, 236, 237, 238, 239, 243, 242, 241, 240}, // Block 3,3 - midi notes: 82,81,80
};
// Define a structure for MIDI-like messages
struct MidiMessage
{
int note;
bool isNoteOn;
};
// Define groups of MIDI-like messages
const std::vector<std::vector<MidiMessage>> midiMessageGroups = {
{
{127, true},
{124, true},
{121, true},
{118, true},
},
{
{115, true},
{112, true},
{109, true},
{106, true},
},
{
{127, false},
{124, false},
{121, false},
{118, false},
},
{
{115, false},
{112, false},
{109, false},
{106, false},
},
{
{127, true},
},
{
{124, true},
},
{
{121, true},
},
{
{118, true},
},
{
{115, true},
},
{
{112, true},
},
{
{109, true},
},
{
{106, true},
},
{{103, true}},
{{100, true}},
{{97, true}},
{{94, true}},
{{91, true}},
{{88, true}},
{{85, true}},
{{82, true}},
{
{127, false},
},
{
{124, false},
},
{
{121, false},
},
{
{118, false},
},
{
{115, false},
},
{
{112, false},
},
{
{109, false},
},
{
{106, false},
},
{{103, false}},
{{100, false}},
{{97, false}},
{{94, false}},
{{91, false}},
{{88, false}},
{{85, false}},
{{82, false}},
{
{127, true},
},
{
{127, false},
},
{
{126, true},
},
{
{126, false},
},
{
{125, true},
},
{
{125, false},
},
{
{127, true},
},
{
{126, true},
},
{
{125, true},
},
{
{127, false},
},
{
{126, false},
},
{
{125, false},
},
};
void setup()
{
Serial.begin(115200);
Serial.println("Hello, ESP32!");
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(255);
}
void setBlockColor(int blockIndex, char color, int value)
{
for (int i = 0; i < LEDS_PER_BLOCK; i++)
{
int ledIndex = ledBlocks[blockIndex][i];
switch (color)
{
case 'r':
leds[ledIndex].r = value;
break;
case 'g':
leds[ledIndex].g = value;
break;
case 'b':
leds[ledIndex].b = value;
break;
}
}
}
void processMidiMessage(const MidiMessage &msg)
{
int blockIndex = (127 - msg.note) / 3;
char color;
switch ((127 - msg.note) % 3)
{
case 0:
color = 'b';
break;
case 1:
color = 'r';
break;
case 2:
color = 'g';
break;
}
int value = msg.isNoteOn ? 255 : 0;
setBlockColor(blockIndex, color, value);
}
void loop()
{
static size_t groupIndex = 0;
// Process all events in the current group
for (const auto &msg : midiMessageGroups[groupIndex])
{
processMidiMessage(msg);
}
// Update LEDs after processing all events in the group
FastLED.show();
// Move to next group
groupIndex = (groupIndex + 1) % midiMessageGroups.size();
delay(100); // Adjust delay as needed
}