Are you attached to that library?
FastLED (providing it works for your LEDs) has a HSV method of addressing the LEDs which would allow you to change between colours for example all with one number (i.e hue of 0 is red, hue of 96 is green etc)
I've mocked this up which seems to be working. I'm using my own enocder.h file here but any will do.
In this, there is one LED (at full brightness and saturation but those would be pretty easy to add in too, as would more LEDs), and the encoder changes the colour. Then, if you press the switch button on the encoder it saves that HSV to an array and prints all of the colours you've saved so far. There's a few 'nice to haves' in regards to the printing etc but you could definitely strip this right down if you wanted.
#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];
struct HSV_Set {
byte hue = 0;
byte saturation = 255;
byte brightness = 255;
};
HSV_Set savedColours[MAX_SAVED_COLOURS];
byte numSavedCols = 0;
HSV_Set editColour;
#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].saturation);
Serial.print(F(") V"));
Serial.print(savedColours[i].brightness);
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] = CHSV(editColour.hue, editColour.saturation, editColour.brightness);
FastLED.show();
}
void loop() {
if (handleEncoders()) { // Only update the LED if the encoder has registered a change
leds[0] = CHSV(editColour.hue, editColour.saturation, editColour.brightness);
FastLED.show();
}
}
Note: This is just how I would approach it (ie possibly not the best way), just practising my coding and posting it on the off chance it's somewhat helpful.
I could see this easily being changed to three encoders, one each for hue, saturation and brightness.
I haven't added anything for selecting and erasing a saved entry but that wouldn't be too hard to add to it. The max saved entries are defined at the top.