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(); }
}
}