#include <OneButton.h>
#include <RotaryEncoder.h>
#include <Adafruit_NeoPixel.h>

RotaryEncoder encoder(A3, A2, RotaryEncoder::LatchMode::TWO03);
Adafruit_NeoPixel *pixels;

OneButton button(9, true);

const int pin = 3, numPixels = 24, MAX_SLIDE_POT_ANALOG_READ_VALUE = 1024;
const int modes = 4, Mute = 0;

int mode = 1, pos[4] = {250, 250, 250, 250}, newPos[4] = {250, 250, 250, 250}, analogSliderValues[modes];
bool Muted[modes] = {false, false, false, false};
byte setPos = 0;

void setup() {
  button.attachClick([] { mode = (mode % modes) + 1; });
  button.attachLongPressStop([] { Muted[mode - 1] = !Muted[mode - 1]; });

  Serial.begin(9600);
  PCICR |= (1 << PCIE1);
  PCMSK1 |= (1 << PCINT10) | (1 << PCINT11);

  pixels = new Adafruit_NeoPixel(numPixels, pin, NEO_GRB + NEO_KHZ800);
  pixels->begin();
  pixels->setBrightness(30);
}

ISR(PCINT1_vect) { encoder.tick(); }

void loop() {
  button.tick();
  if (setPos != mode) {
    setPos = mode;
    encoder.setPosition(pos[mode - 1]);
  }
  newPos[mode - 1] = encoder.getPosition();
  if (pos[mode - 1] != newPos[mode - 1]) {
    pos[mode - 1] = newPos[mode - 1];
  }
  analogSliderValues[mode - 1] = Muted[mode - 1] ? Mute : newPos[mode - 1];
  updatePixels();
  sendSliderValues();
  printSliderValues();
  delay(20);
}

void updatePixels() {
  int value_pot_a = pos[mode - 1];
  int num_leds_switchedon = map(value_pot_a, 0, MAX_SLIDE_POT_ANALOG_READ_VALUE, 0, numPixels - 1);
  uint32_t color = (mode == 1) ? pixels->Color(150, 150, 150) :
                   (mode == 2) ? pixels->Color(150, 100, 0) :
                   (mode == 3) ? pixels->Color(0, 0, 150) :
                                 pixels->Color(150, 0, 0);
  for (int i = 0; i < num_leds_switchedon; ++i) pixels->setPixelColor(i, color);
  for (int i = num_leds_switchedon; i < numPixels - 1; ++i) pixels->setPixelColor(i, pixels->Color(0, 0, 0));
  pixels->setPixelColor(23, Muted[mode - 1] ? pixels->Color(255, 0, 0) : pixels->Color(0, 0, 0));
  pixels->show();
}

void sendSliderValues() {
  String builtString = "";
  for (int i = 0; i < mode; i++) {
    builtString += String(analogSliderValues[i]);
    if (i < mode - 1) builtString += "|";
  }
  Serial.println(builtString);
}

void printSliderValues() {
  for (int i = 0; i < modes; i++) {
    Serial.print("Slider #" + String(i + 1) + ": " + String(analogSliderValues[i]) + " mV");
    if (i < modes - 1) Serial.print(" | ");
    else Serial.println();
  }
}
Missing chipchip-eeprom-24lc256