Code improvement and eliminate String use

Hello,

The code below achieves what I want, but using the string option uses too much memory and will not function correctly. If i reduce the code down by eliminating some of the LED's then it functions correctly. I have searched the forum and understand that using the String is not recommended, but I am not sure how to achieve the desired results in another way. I have tried several different attempts with if statements or using switch statements, but not with achieving what I need. I appreciate any advice or support provided

Board: Uno R3

Code Function
The code below takes user input from the serial monitor or windows form to illuminate a single LED on a LED strip. Each LED location can be lit with five different color options depending on the character in the 5th spot of the string. The string names (A001-B024) are name place holders that I can use for programming the Windows Form (not built yet) that will equate to the user input.

#include <FastLED.h>
#include <string.h>
#define DATA_PIN 7
#define NUM_LEDS 100
#define BRIGHTNESS  50
CRGB leds[NUM_LEDS];
//void setup() { FastLED.addLeds<NEOPIXEL, 7>(leds, NUM_LEDS); }


void setup() {
  Serial.begin(9600);
  Serial.println("SK6812 LEDs strip Initialize");
  Serial.println("Enter Location");
  
  FastLED.addLeds<SK6812, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical
  FastLED.setBrightness( BRIGHTNESS );
  FastLED.clear();
  FastLED.show();
  
}
String input;
void loop() {
  if (Serial.available() > 0) {
    input = Serial.readString();
    input.trim();
    FastLED.clear();
    FastLED.show();

    //A001
    if (input == "A001"){  leds[48] = CRGB::Cyan; FastLED.show();    }
    if (input == "A001B"){  leds[48] = CRGB::Blue; FastLED.show();    }
    if (input == "A001R"){  leds[48] = CRGB::Red; FastLED.show();    }
    if (input == "A001G"){  leds[48] = CRGB::Green; FastLED.show();    }
    if (input == "A001Y"){  leds[48] = CRGB::Yellow; FastLED.show();    }
    //A002
    if (input == "A002"){  leds[46] = CRGB::Cyan; FastLED.show();    }
    if (input == "A002B"){  leds[46] = CRGB::Blue; FastLED.show();    }
    if (input == "A002R"){  leds[46] = CRGB::Red; FastLED.show();    }
    if (input == "A002G"){  leds[46] = CRGB::Green; FastLED.show();    }
    if (input == "A002Y"){  leds[46] = CRGB::Yellow; FastLED.show();    }
    //A003
    if (input == "A003"){  leds[44] = CRGB::Cyan; FastLED.show();    }
    if (input == "A003B"){  leds[44] = CRGB::Blue; FastLED.show();    }
    if (input == "A003R"){  leds[44] = CRGB::Red; FastLED.show();    }
    if (input == "A003G"){  leds[44] = CRGB::Green; FastLED.show();    }
    if (input == "A003Y"){  leds[44] = CRGB::Yellow; FastLED.show();    }
    //A004
    if (input == "A004"){  leds[42] = CRGB::Cyan; FastLED.show();    }
    if (input == "A004B"){  leds[42] = CRGB::Blue; FastLED.show();    }
    if (input == "A004R"){  leds[42] = CRGB::Red; FastLED.show();    }
    if (input == "A004G"){  leds[42] = CRGB::Green; FastLED.show();    }
    if (input == "A004Y"){  leds[42] = CRGB::Yellow; FastLED.show();    }
    //A005
    if (input == "A005"){  leds[40] = CRGB::Cyan; FastLED.show();    }
    if (input == "A005B"){  leds[40] = CRGB::Blue; FastLED.show();    }
    if (input == "A005R"){  leds[40] = CRGB::Red; FastLED.show();    }
    if (input == "A005G"){  leds[40] = CRGB::Green; FastLED.show();    }
    if (input == "A005Y"){  leds[40] = CRGB::Yellow; FastLED.show();    }
    //A006
    if (input == "A006"){  leds[38] = CRGB::Cyan; FastLED.show();    }
    if (input == "A006B"){  leds[38] = CRGB::Blue; FastLED.show();    }
    if (input == "A006R"){  leds[38] = CRGB::Red; FastLED.show();    }
    if (input == "A006G"){  leds[38] = CRGB::Green; FastLED.show();    }
    if (input == "A006Y"){  leds[38] = CRGB::Yellow; FastLED.show();    }
    //A007
    if (input == "A007"){  leds[36] = CRGB::Cyan; FastLED.show();    }
    if (input == "A007B"){  leds[36] = CRGB::Blue; FastLED.show();    }
    if (input == "A007R"){  leds[36] = CRGB::Red; FastLED.show();    }
    if (input == "A007G"){  leds[36] = CRGB::Green; FastLED.show();    }
    if (input == "A007Y"){  leds[36] = CRGB::Yellow; FastLED.show();    }
    //A008
    if (input == "A008"){  leds[34] = CRGB::Cyan; FastLED.show();    }
    if (input == "A008B"){  leds[34] = CRGB::Blue; FastLED.show();    }
    if (input == "A008R"){  leds[34] = CRGB::Red; FastLED.show();    }
    if (input == "A008G"){  leds[34] = CRGB::Green; FastLED.show();    }
    if (input == "A008Y"){  leds[34] = CRGB::Yellow; FastLED.show();    }
    //A009
    if (input == "A009"){  leds[31] = CRGB::Cyan; FastLED.show();    }
    if (input == "A009B"){  leds[31] = CRGB::Blue; FastLED.show();    }
    if (input == "A009R"){  leds[31] = CRGB::Red; FastLED.show();    }
    if (input == "A009G"){  leds[31] = CRGB::Green; FastLED.show();    }
    if (input == "A009Y"){  leds[31] = CRGB::Yellow; FastLED.show();    }
    //A010
    if (input == "A010"){  leds[29] = CRGB::Cyan; FastLED.show();    }
    if (input == "A010B"){  leds[29] = CRGB::Blue; FastLED.show();    }
    if (input == "A010R"){  leds[29] = CRGB::Red; FastLED.show();    }
    if (input == "A010G"){  leds[29] = CRGB::Green; FastLED.show();    }
    if (input == "A010Y"){  leds[29] = CRGB::Yellow; FastLED.show();    }
    //A011
    if (input == "A011"){  leds[27] = CRGB::Cyan; FastLED.show();    }
    if (input == "A011B"){  leds[27] = CRGB::Blue; FastLED.show();    }
    if (input == "A011R"){  leds[27] = CRGB::Red; FastLED.show();    }
    if (input == "A011G"){  leds[27] = CRGB::Green; FastLED.show();    }
    if (input == "A011Y"){  leds[27] = CRGB::Yellow; FastLED.show();    }
    //A012
    if (input == "A012"){  leds[25] = CRGB::Cyan; FastLED.show();    }
    if (input == "A012B"){  leds[25] = CRGB::Blue; FastLED.show();    }
    if (input == "A012R"){  leds[25] = CRGB::Red; FastLED.show();    }
    if (input == "A012G"){  leds[25] = CRGB::Green; FastLED.show();    }
    if (input == "A012Y"){  leds[25] = CRGB::Yellow; FastLED.show();    }
    //A013
    if (input == "A013"){  leds[23] = CRGB::Cyan; FastLED.show();    }
    if (input == "A013B"){  leds[23] = CRGB::Blue; FastLED.show();    }
    if (input == "A013R"){  leds[23] = CRGB::Red; FastLED.show();    }
    if (input == "A013G"){  leds[23] = CRGB::Green; FastLED.show();    }
    if (input == "A013Y"){  leds[23] = CRGB::Yellow; FastLED.show();    }
    //A014
    if (input == "A014"){  leds[21] = CRGB::Cyan; FastLED.show();    }
    if (input == "A014B"){  leds[21] = CRGB::Blue; FastLED.show();    }
    if (input == "A014R"){  leds[21] = CRGB::Red; FastLED.show();    }
    if (input == "A014G"){  leds[21] = CRGB::Green; FastLED.show();    }
    if (input == "A014Y"){  leds[21] = CRGB::Yellow; FastLED.show();    }
    //A015
    if (input == "A015"){  leds[19] = CRGB::Cyan; FastLED.show();    }
    if (input == "A015B"){  leds[19] = CRGB::Blue; FastLED.show();    }
    if (input == "A015R"){  leds[19] = CRGB::Red; FastLED.show();    }
    if (input == "A015G"){  leds[19] = CRGB::Green; FastLED.show();    }
    if (input == "A015Y"){  leds[19] = CRGB::Yellow; FastLED.show();    }
    //A016
    if (input == "A016"){  leds[17] = CRGB::Cyan; FastLED.show();    }
    if (input == "A016B"){  leds[17] = CRGB::Blue; FastLED.show();    }
    if (input == "A016R"){  leds[17] = CRGB::Red; FastLED.show();    }
    if (input == "A016G"){  leds[17] = CRGB::Green; FastLED.show();    }
    if (input == "A016Y"){  leds[17] = CRGB::Yellow; FastLED.show();    }
    //A017
    if (input == "A017"){  leds[14] = CRGB::Cyan; FastLED.show();    }
    if (input == "A017B"){  leds[14] = CRGB::Blue; FastLED.show();    }
    if (input == "A017R"){  leds[14] = CRGB::Red; FastLED.show();    }
    if (input == "A017G"){  leds[14] = CRGB::Green; FastLED.show();    }
    if (input == "A017Y"){  leds[14] = CRGB::Yellow; FastLED.show();    }
    //A018
    if (input == "A018"){  leds[12] = CRGB::Cyan; FastLED.show();    }
    if (input == "A018B"){  leds[12] = CRGB::Blue; FastLED.show();    }
    if (input == "A018R"){  leds[12] = CRGB::Red; FastLED.show();    }
    if (input == "A018G"){  leds[12] = CRGB::Green; FastLED.show();    }
    if (input == "A018Y"){  leds[12] = CRGB::Yellow; FastLED.show();    }
    //A019
    if (input == "A019"){  leds[10] = CRGB::Cyan; FastLED.show();    }
    if (input == "A019B"){  leds[10] = CRGB::Blue; FastLED.show();    }
    if (input == "A019R"){  leds[10] = CRGB::Red; FastLED.show();    }
    if (input == "A019G"){  leds[10] = CRGB::Green; FastLED.show();    }
    if (input == "A019Y"){  leds[10] = CRGB::Yellow; FastLED.show();    }
    //A020
    if (input == "A020"){  leds[8] = CRGB::Cyan; FastLED.show();    }
    if (input == "A020B"){  leds[8] = CRGB::Blue; FastLED.show();    }
    if (input == "A020R"){  leds[8] = CRGB::Red; FastLED.show();    }
    if (input == "A020G"){  leds[8] = CRGB::Green; FastLED.show();    }
    if (input == "A020Y"){  leds[8] = CRGB::Yellow; FastLED.show();    }
    //A021
    if (input == "A021"){  leds[6] = CRGB::Cyan; FastLED.show();    }
    if (input == "A021B"){  leds[6] = CRGB::Blue; FastLED.show();    }
    if (input == "A021R"){  leds[6] = CRGB::Red; FastLED.show();    }
    if (input == "A021G"){  leds[6] = CRGB::Green; FastLED.show();    }
    if (input == "A021Y"){  leds[6] = CRGB::Yellow; FastLED.show();    }
    //A022
    if (input == "A022"){  leds[4] = CRGB::Cyan; FastLED.show();    }
    if (input == "A022B"){  leds[4] = CRGB::Blue; FastLED.show();    }
    if (input == "A022R"){  leds[4] = CRGB::Red; FastLED.show();    }
    if (input == "A022G"){  leds[4] = CRGB::Green; FastLED.show();    }
    if (input == "A022Y"){  leds[4] = CRGB::Yellow; FastLED.show();    }
    //A023
    if (input == "A023"){  leds[2] = CRGB::Cyan; FastLED.show();    }
    if (input == "A023B"){  leds[2] = CRGB::Blue; FastLED.show();    }
    if (input == "A023R"){  leds[2] = CRGB::Red; FastLED.show();    }
    if (input == "A023G"){  leds[2] = CRGB::Green; FastLED.show();    }
    if (input == "A023Y"){  leds[2] = CRGB::Yellow; FastLED.show();    }
    //A024
    if (input == "A024"){  leds[0] = CRGB::Cyan; FastLED.show();    }
    if (input == "A024B"){  leds[0] = CRGB::Blue; FastLED.show();    }
    if (input == "A024R"){  leds[0] = CRGB::Red; FastLED.show();    }
    if (input == "A024G"){  leds[0] = CRGB::Green; FastLED.show();    }
    if (input == "A024Y"){  leds[0] = CRGB::Yellow; FastLED.show();    }
    //B001
    if (input == "B001"){  leds[51] = CRGB::Cyan; FastLED.show();    }
    if (input == "B001B"){  leds[51] = CRGB::Blue; FastLED.show();    }
    if (input == "B001R"){  leds[51] = CRGB::Red; FastLED.show();    }
    if (input == "B001G"){  leds[51] = CRGB::Green; FastLED.show();    }
    if (input == "B001Y"){  leds[51] = CRGB::Yellow; FastLED.show();    }
    //B002
    if (input == "B002"){  leds[53] = CRGB::Cyan; FastLED.show();    }
    if (input == "B002B"){  leds[53] = CRGB::Blue; FastLED.show();    }
    if (input == "B002R"){  leds[53] = CRGB::Red; FastLED.show();    }
    if (input == "B002G"){  leds[53] = CRGB::Green; FastLED.show();    }
    if (input == "B002Y"){  leds[53] = CRGB::Yellow; FastLED.show();    }
    //B003
    if (input == "B003"){  leds[55] = CRGB::Cyan; FastLED.show();    }
    if (input == "B003B"){  leds[55] = CRGB::Blue; FastLED.show();    }
    if (input == "B003R"){  leds[55] = CRGB::Red; FastLED.show();    }
    if (input == "B003G"){  leds[55] = CRGB::Green; FastLED.show();    }
    if (input == "B003Y"){  leds[55] = CRGB::Yellow; FastLED.show();    }
    //B004
    if (input == "B004"){  leds[57] = CRGB::Cyan; FastLED.show();    }
    if (input == "B004B"){  leds[57] = CRGB::Blue; FastLED.show();    }
    if (input == "B004R"){  leds[57] = CRGB::Red; FastLED.show();    }
    if (input == "B004G"){  leds[57] = CRGB::Green; FastLED.show();    }
    if (input == "B004Y"){  leds[57] = CRGB::Yellow; FastLED.show();    }
    //B005
    if (input == "B005"){  leds[59] = CRGB::Cyan; FastLED.show();    }
    if (input == "B005B"){  leds[59] = CRGB::Blue; FastLED.show();    }
    if (input == "B005R"){  leds[59] = CRGB::Red; FastLED.show();    }
    if (input == "B005G"){  leds[59] = CRGB::Green; FastLED.show();    }
    if (input == "B005Y"){  leds[59] = CRGB::Yellow; FastLED.show();    }
    //B006
    if (input == "B006"){  leds[61] = CRGB::Cyan; FastLED.show();    }
    if (input == "B006B"){  leds[61] = CRGB::Blue; FastLED.show();    }
    if (input == "B006R"){  leds[61] = CRGB::Red; FastLED.show();    }
    if (input == "B006G"){  leds[61] = CRGB::Green; FastLED.show();    }
    if (input == "B006Y"){  leds[61] = CRGB::Yellow; FastLED.show();    }
    //B007
    if (input == "B007"){  leds[63] = CRGB::Cyan; FastLED.show();    }
    if (input == "B007B"){  leds[63] = CRGB::Blue; FastLED.show();    }
    if (input == "B007R"){  leds[63] = CRGB::Red; FastLED.show();    }
    if (input == "B007G"){  leds[63] = CRGB::Green; FastLED.show();    }
    if (input == "B007Y"){  leds[63] = CRGB::Yellow; FastLED.show();    }
    //B008
    if (input == "B008"){  leds[65] = CRGB::Cyan; FastLED.show();    }
    if (input == "B008B"){  leds[65] = CRGB::Blue; FastLED.show();    }
    if (input == "B008R"){  leds[65] = CRGB::Red; FastLED.show();    }
    if (input == "B008G"){  leds[65] = CRGB::Green; FastLED.show();    }
    if (input == "B008Y"){  leds[65] = CRGB::Yellow; FastLED.show();    }
    //B009
    if (input == "B009"){  leds[68] = CRGB::Cyan; FastLED.show();    }
    if (input == "B009B"){  leds[68] = CRGB::Blue; FastLED.show();    }
    if (input == "B009R"){  leds[68] = CRGB::Red; FastLED.show();    }
    if (input == "B009G"){  leds[68] = CRGB::Green; FastLED.show();    }
    if (input == "B009Y"){  leds[68] = CRGB::Yellow; FastLED.show();    }
    //B010
    if (input == "B010"){  leds[70] = CRGB::Cyan; FastLED.show();    }
    if (input == "B010B"){  leds[70] = CRGB::Blue; FastLED.show();    }
    if (input == "B010R"){  leds[70] = CRGB::Red; FastLED.show();    }
    if (input == "B010G"){  leds[70] = CRGB::Green; FastLED.show();    }
    if (input == "B010Y"){  leds[70] = CRGB::Yellow; FastLED.show();    }
    //B011
    if (input == "B011"){  leds[72] = CRGB::Cyan; FastLED.show();    }
    if (input == "B011B"){  leds[72] = CRGB::Blue; FastLED.show();    }
    if (input == "B011R"){  leds[72] = CRGB::Red; FastLED.show();    }
    if (input == "B011G"){  leds[72] = CRGB::Green; FastLED.show();    }
    if (input == "B011Y"){  leds[72] = CRGB::Yellow; FastLED.show();    }
    //B012
    if (input == "B012"){  leds[74] = CRGB::Cyan; FastLED.show();    }
    if (input == "B012B"){  leds[74] = CRGB::Blue; FastLED.show();    }
    if (input == "B012R"){  leds[74] = CRGB::Red; FastLED.show();    }
    if (input == "B012G"){  leds[74] = CRGB::Green; FastLED.show();    }
    if (input == "B012Y"){  leds[74] = CRGB::Yellow; FastLED.show();    }
    //B013
    if (input == "B013"){  leds[76] = CRGB::Cyan; FastLED.show();    }
    if (input == "B013B"){  leds[76] = CRGB::Blue; FastLED.show();    }
    if (input == "B013R"){  leds[76] = CRGB::Red; FastLED.show();    }
    if (input == "B013G"){  leds[76] = CRGB::Green; FastLED.show();    }
    if (input == "B013Y"){  leds[76] = CRGB::Yellow; FastLED.show();    }
    //B014
    if (input == "B014"){  leds[78] = CRGB::Cyan; FastLED.show();    }
    if (input == "B014B"){  leds[78] = CRGB::Blue; FastLED.show();    }
    if (input == "B014R"){  leds[78] = CRGB::Red; FastLED.show();    }
    if (input == "B014G"){  leds[78] = CRGB::Green; FastLED.show();    }
    if (input == "B014Y"){  leds[78] = CRGB::Yellow; FastLED.show();    }
    //B015
    if (input == "B015"){  leds[80] = CRGB::Cyan; FastLED.show();    }
    if (input == "B015B"){  leds[80] = CRGB::Blue; FastLED.show();    }
    if (input == "B015R"){  leds[80] = CRGB::Red; FastLED.show();    }
    if (input == "B015G"){  leds[80] = CRGB::Green; FastLED.show();    }
    if (input == "B015Y"){  leds[80] = CRGB::Yellow; FastLED.show();    }
    //B016
    if (input == "B016"){  leds[82] = CRGB::Cyan; FastLED.show();    }
    if (input == "B016B"){  leds[82] = CRGB::Blue; FastLED.show();    }
    if (input == "B016R"){  leds[82] = CRGB::Red; FastLED.show();    }
    if (input == "B016G"){  leds[82] = CRGB::Green; FastLED.show();    }
    if (input == "B016Y"){  leds[82] = CRGB::Yellow; FastLED.show();    }
    //B017
    if (input == "B017"){  leds[85] = CRGB::Cyan; FastLED.show();    }
    if (input == "B017B"){  leds[85] = CRGB::Blue; FastLED.show();    }
    if (input == "B017R"){  leds[85] = CRGB::Red; FastLED.show();    }
    if (input == "B017G"){  leds[85] = CRGB::Green; FastLED.show();    }
    if (input == "B017Y"){  leds[85] = CRGB::Yellow; FastLED.show();    }
    //B018
    if (input == "B018"){  leds[87] = CRGB::Cyan; FastLED.show();    }
    if (input == "B018B"){  leds[87] = CRGB::Blue; FastLED.show();    }
    if (input == "B018R"){  leds[87] = CRGB::Red; FastLED.show();    }
    if (input == "B018G"){  leds[87] = CRGB::Green; FastLED.show();    }
    if (input == "B018Y"){  leds[87] = CRGB::Yellow; FastLED.show();    }
    //B019
    if (input == "B019"){  leds[89] = CRGB::Cyan; FastLED.show();    }
    if (input == "B019B"){  leds[89] = CRGB::Blue; FastLED.show();    }
    if (input == "B019R"){  leds[89] = CRGB::Red; FastLED.show();    }
    if (input == "B019G"){  leds[89] = CRGB::Green; FastLED.show();    }
    if (input == "B019Y"){  leds[89] = CRGB::Yellow; FastLED.show();    }
    //B020
    if (input == "B020"){  leds[91] = CRGB::Cyan; FastLED.show();    }
    if (input == "B020B"){  leds[91] = CRGB::Blue; FastLED.show();    }
    if (input == "B020R"){  leds[91] = CRGB::Red; FastLED.show();    }
    if (input == "B020G"){  leds[91] = CRGB::Green; FastLED.show();    }
    if (input == "B020Y"){  leds[91] = CRGB::Yellow; FastLED.show();    }
    //B021
    if (input == "B021"){  leds[93] = CRGB::Cyan; FastLED.show();    }
    if (input == "B021B"){  leds[93] = CRGB::Blue; FastLED.show();    }
    if (input == "B021R"){  leds[93] = CRGB::Red; FastLED.show();    }
    if (input == "B021G"){  leds[93] = CRGB::Green; FastLED.show();    }
    if (input == "B021Y"){  leds[93] = CRGB::Yellow; FastLED.show();    }
    //B022
    if (input == "B022"){  leds[95] = CRGB::Cyan; FastLED.show();    }
    if (input == "B022B"){  leds[95] = CRGB::Blue; FastLED.show();    }
    if (input == "B022R"){  leds[95] = CRGB::Red; FastLED.show();    }
    if (input == "B022G"){  leds[95] = CRGB::Green; FastLED.show();    }
    if (input == "B022Y"){  leds[95] = CRGB::Yellow; FastLED.show();    }
    //B023
    if (input == "B023"){  leds[97] = CRGB::Cyan; FastLED.show();    }
    if (input == "B023B"){  leds[97] = CRGB::Blue; FastLED.show();    }
    if (input == "B023R"){  leds[97] = CRGB::Red; FastLED.show();    }
    if (input == "B023G"){  leds[97] = CRGB::Green; FastLED.show();    }
    if (input == "B023Y"){  leds[97] = CRGB::Yellow; FastLED.show();    }
    //B024
    if (input == "B024"){  leds[99] = CRGB::Cyan; FastLED.show();    }
    if (input == "B024B"){  leds[99] = CRGB::Blue; FastLED.show();    }
    if (input == "B024R"){  leds[99] = CRGB::Red; FastLED.show();    }
    if (input == "B024G"){  leds[99] = CRGB::Green; FastLED.show();    }
    if (input == "B024Y"){  leds[99] = CRGB::Yellow; FastLED.show();    }
  
  }
}

c-strings:

look this over
17% program, 41% ram w/o LED library

struct Code {
    const char *code;
    int         idx;
};
Code codes [] = {
    { "A001", 48 },
    { "A002", 46 },
    { "A003", 44 },
    { "A004", 42 },
    { "A005", 40 },
    { "A006", 38 },
    { "A007", 36 },
    { "A008", 34 },
    { "A009", 31 },
    { "A010", 29 },
    { "A011", 27 },
    { "A012", 25 },
    { "A013", 23 },
    { "A014", 21 },
    { "A015", 19 },
    { "A016", 17 },
    { "A017", 14 },
    { "A018", 12 },
    { "A019", 10 },
    { "A020",  8 },
    { "A021",  6 },
    { "A022",  4 },
    { "A023",  2 },
    { "A024",  0 },
    { "B001", 51 },
    { "B002", 53 },
    { "B003", 55 },
    { "B004", 57 },
    { "B005", 59 },
    { "B006", 61 },
    { "B007", 63 },
    { "B008", 65 },
    { "B009", 68 },
    { "B010", 70 },
    { "B011", 72 },
    { "B012", 74 },
    { "B013", 76 },
    { "B014", 78 },
    { "B015", 80 },
    { "B016", 82 },
    { "B017", 85 },
    { "B018", 87 },
    { "B019", 89 },
    { "B020", 91 },
    { "B021", 93 },
    { "B022", 95 },
    { "B023", 97 },
    { "B024", 99 },
};
int Ncode = sizeof(codes)/sizeof(Code);

char s [90];

// -----------------------------------------------------------------------------
void
showLed (
    const char *code,
    int         idx )
{
    switch (code [4]) {
    case 'B':
        sprintf (s, "showLed %2d Blue", idx);
        break;
    case 'R':
        sprintf (s, "showLed %2d Red", idx);
        break;
    case 'G':
        sprintf (s, "showLed %2d Green", idx);
        break;
    case 'Y':
        sprintf (s, "showLed %2d Yellow", idx);
        break;
    case 0:
        sprintf (s, "showLed %2d Cyan", idx);
        break;
    default:
        sprintf (s, "showLed: invalid suffix - %c", code [4]);
        Serial.println (s);
        return;
    }

    Serial.println (s);
}

// -----------------------------------------------------------------------------
int
findCode (
    const char *s)
{
    for (int n = 0; n < Ncode; n++)  {
        if (! strncmp (s, codes [n].code, 4))
            return codes [n].idx;
    }
    return -1;
}

// -----------------------------------------------------------------------------
void loop() {
    if (Serial.available() > 0) {
        char buf [90];
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';

        int idx = findCode (buf);
        if (0 > idx)
            Serial.println ("loop: unknown code");
        else
            showLed (buf, idx);
    }
}

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(9600);
}

Thank you for your response. It compiles as you said and seems to save on a lot of memory. I haven't tried to illuminate any LED's outside of the FastLED or AdaFruit libraries before. I am assuming I need to use this code with one of those libraries? I apologize, I am new to Adruino and programming. I just have been trying to get this to work right for over a week now.

Why not parse the string command?

1 Like

you need to set the led [] color and call FastLED.show() in the showLed() function i posted.

i don't post code i can't test

The commands

follow a pattern

This means the letters can be reduced to
{ "B12", 74 },

And the pure informations
there is a
LED-strip "A"
and a LED-strip "B"
can be stored in a single byte

And the numbers can be stored in a second byte as a byte-value 1,2,3
the color can be stored in a third byte
So parsing the received data is reduced to 3 compare bytes from
if (StripNr == 1)
if (StripNr == 2)

LED-Nr is directly byte 2
color is byte 3 which could be an array of the colors
then the index represents the index in the array

ColorIdx

In this short description I guess it is hard to understand for beginners.
So depending on how much memory you must save and depending on how much fun / or no fun you have in learning somehow more advanced programming techniques you could ask for the details how this is done.

The information "A" / "B" could be stored as 1,2,3.......24 and 100,101,102,...124
so everything boils down on parsing two bytes

1 Like

version using less RAM
21% program, 25% ram

struct Code {
    byte  idxA;
    byte  idxB;
};
Code codes [] = {
    { },                // index 0
    {    48,   51 },
    {    46,   53 },
    {    44,   55 },
    {    42,   57 },
    {    40,   59 },
    {    38,   61 },
    {    36,   63 },
    {    34,   65 },
    {    31,   68 },
    {    29,   70 },
    {    27,   72 },
    {    25,   74 },
    {    23,   76 },
    {    21,   78 },
    {    19,   80 },
    {    17,   82 },
    {    14,   85 },
    {    12,   87 },
    {    10,   89 },
    {     8,   91 },
    {     6,   93 },
    {     4,   95 },
    {     2,   97 },
    {     0,   99 },
};
int Ncode = sizeof(codes)/sizeof(Code);

char s [90];

// -----------------------------------------------------------------------------
void
showLed (
    char prefix,
    int  id,
    char sufix )
{
    int idx;

    if (0 == id || Ncode <= id)  {
        sprintf (s, "Error - showLed - invalid id, %d", id); 
        Serial.println (s);
        return;
    }

    if ('A' == prefix)
        idx = codes [id].idxA;
    else if ('B' == prefix)
        idx = codes [id].idxB;
    else {
        sprintf (s, "Error - showLed - invalid prefix, %c", prefix); 
        Serial.println (s);
        return;
    }

    switch (sufix) {
    case 'B':
        sprintf (s, "showLed %2d Blue", idx);
        break;
    case 'R':
        sprintf (s, "showLed %2d Red", idx);
        break;
    case 'G':
        sprintf (s, "showLed %2d Green", idx);
        break;
    case 'Y':
        sprintf (s, "showLed %2d Yellow", idx);
        break;
    case 0:
        sprintf (s, "showLed %2d Cyan", idx);
        break;
    default:
        sprintf (s, "Error - showLed - invalid sufix, %c", sufix); 
        Serial.println (s);
        return;
    }

    Serial.println (s);
}

// -----------------------------------------------------------------------------
void loop() {
    if (Serial.available() > 0) {
        char buf [90];
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';

        char prefix;
        char sufix = 0;
        int  id;
        sscanf (buf, "%c%d%c", &prefix, &id, & sufix);
        showLed (prefix, id, sufix);
    }
}

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(9600);
}
1 Like

Thank you @gcjr. I added in the FastLED code and it works great.

#include <FastLED.h>
#define DATA_PIN 7
#define NUM_LEDS 100
#define BRIGHTNESS  50
CRGB leds[NUM_LEDS];


struct Code {
    const char *code;
    int         idx;
};
Code codes [] = {
    { "A001", 48 },
    { "A002", 46 },
    { "A003", 44 },
    { "A004", 42 },
    { "A005", 40 },
    { "A006", 38 },
    { "A007", 36 },
    { "A008", 34 },
    { "A009", 31 },
    { "A010", 29 },
    { "A011", 27 },
    { "A012", 25 },
    { "A013", 23 },
    { "A014", 21 },
    { "A015", 19 },
    { "A016", 17 },
    { "A017", 14 },
    { "A018", 12 },
    { "A019", 10 },
    { "A020",  8 },
    { "A021",  6 },
    { "A022",  4 },
    { "A023",  2 },
    { "A024",  0 },
    { "B001", 51 },
    { "B002", 53 },
    { "B003", 55 },
    { "B004", 57 },
    { "B005", 59 },
    { "B006", 61 },
    { "B007", 63 },
    { "B008", 65 },
    { "B009", 68 },
    { "B010", 70 },
    { "B011", 72 },
    { "B012", 74 },
    { "B013", 76 },
    { "B014", 78 },
    { "B015", 80 },
    { "B016", 82 },
    { "B017", 85 },
    { "B018", 87 },
    { "B019", 89 },
    { "B020", 91 },
    { "B021", 93 },
    { "B022", 95 },
    { "B023", 97 },
    { "B024", 99 },
};
int Ncode = sizeof(codes)/sizeof(Code);

char s [90];

// -----------------------------------------------------------------------------
void
showLed (
    const char *code,
    int         idx )
{
    switch (code [4]) {
    case 'B':
        sprintf (s, "showLed %2d Blue", idx);
        leds[idx] = CRGB::Blue; FastLED.show();
        break;
    case 'R':
        sprintf (s, "showLed %2d Red", idx);
        leds[idx] = CRGB::Red; FastLED.show();
        break;
    case 'G':
        sprintf (s, "showLed %2d Green", idx);
        leds[idx] = CRGB::Green; FastLED.show();
        break;
    case 'Y':
        sprintf (s, "showLed %2d Yellow", idx);
        leds[idx] = CRGB::Yellow; FastLED.show();
        break;
    case 0:
        sprintf (s, "showLed %2d Cyan", idx);
        leds[idx] = CRGB::Cyan; FastLED.show();
        break;
    default:
        sprintf (s, "showLed: invalid suffix - %c", code [4]);
        Serial.println (s);
        leds[NUM_LEDS] = CRGB::Black; FastLED.show();
        
        return;
    }

    Serial.println (s);
}

// -----------------------------------------------------------------------------
int
findCode (
    const char *s)
{
    for (int n = 0; n < Ncode; n++)  {
        if (! strncmp (s, codes [n].code, 4))
            return codes [n].idx;
    }
    return -1;
}

// -----------------------------------------------------------------------------
void loop() {
    if (Serial.available() > 0) {
    FastLED.clear();
    FastLED.show();

        char buf [90];
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';

        int idx = findCode (buf);
        if (0 > idx)
            Serial.println ("loop: unknown code");
        else
            showLed (buf, idx);
    }
}

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(9600);
    Serial.println("Enter Location");

    FastLED.addLeds<SK6812, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical
    FastLED.setBrightness( BRIGHTNESS );
    FastLED.clear();
    FastLED.show();
    

}

I plan to expand from 48 LED locations to 300, so I will definitely experiment with the updated code that uses even less ram.

thanks to suggestions by @build_1971 and @StefanL38

1 Like

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