LED control with Neopixel library and Encoder

Yeah I should have twigged that! :joy:

Updated:

#define ARRSIZE(x) sizeof(x) / sizeof(x[0])

#define NUM_LEDS 1
#define MAX_SAVED_COLOURS 15
#define ADJUSTMENT_VALUE 10 // Must be less than 255!

#include <FastLED.h>
#define DATA_PIN 12
CRGB leds[NUM_LEDS];


CHSV savedColours[MAX_SAVED_COLOURS];
byte numSavedCols = 0;

CHSV editColour = { 0, 255, 255 };

#include "encoder.h"
Encoder encoders[] = { { 14, 26, 13 } };
const byte NUM_ENC = ARRSIZE(encoders);



ActionType handleEncoders() {
  ActionType action;
  for (byte i = 0; i < NUM_ENC; i++) {
    action = encoders[i].read();
    switch (action) {
      case NOTHING:
        break;

      case INCREASE:
        editColour.hue += ADJUSTMENT_VALUE;
        break;

      case DECREASE:
        editColour.hue += -ADJUSTMENT_VALUE;
        break;

      case SINGLE_PRESS:
        if (saveCurrentColour()) {
          printSavedColours();
        }
        else
          printSaveError();
        break;
    }
  }
  return action;
}

void printSaveError() {
  Serial.println(F("========================================"));
  Serial.println(F(" ERR! - Max Saves Reached! "));
  Serial.println(F("========================================"));
}

bool saveCurrentColour() {
  if (numSavedCols <= MAX_SAVED_COLOURS - 1) { // Only save if we're under capacity
    savedColours[numSavedCols] = editColour;
    Serial.println(F("========================================"));
    Serial.println(F(" Colour Saved! "));
    numSavedCols++;
    return true;
  }
  else
    return false;
}

void printSavedColours() {
  Serial.println(F("========================================"));
  for (byte i = 0; i < numSavedCols; i++) {
    Serial.print(F(" List: Saved Colour "));
    Serial.print(i);
    Serial.print(F(" = H("));
    Serial.print(savedColours[i].hue);
    Serial.print(F(") S("));
    Serial.print(savedColours[i].sat);
    Serial.print(F(") V"));
    Serial.print(savedColours[i].val);
    Serial.println(F(")"));
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(DATA_PIN, OUTPUT);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  // Initially show the LED;
  leds[0] = editColour;
  FastLED.show();
}

void loop() {
  if (handleEncoders()) { // Only update the LED if the encoder has registered a change
    leds[0] = editColour;
    FastLED.show();
  }
}

See it in action: sketch.ino - Wokwi ESP32, STM32, Arduino Simulator
(click play, click on the white area of the encoder, then you can use the left/right keyboard buttons to increase/decrease and space bar to 'save' and print)