[Solved]LED Strip with arrays

Hello. I need to light groups of leds on a strip. I am using Fastled library and Neopixel.

Searching on the net I found something like this

#include <FastLED.h>
#include <Adafruit_NeoPixel.h>

#define NUM_LEDS 80
#define DATA_PIN 4
CRGB leds[NUM_LEDS];
#define COLOR_ORDER BGR
#define BRIGHTNESS  20


//THESE ARE MY LED ARRAYS
int myLEDs0[ ] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
int myLEDs1[ ] = {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
int myLEDs2[ ] = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59};
int myLEDs3[ ] = {60, 61, 62, 63, 64, 65, 66, 67, 68, 83, 84, 85, 86, 86, 87, 88};
int myLEDs4[ ] = {69, 70, 77, 78, 79, 80, 81, 82, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98};
int myLEDs5[] = {71, 72, 73, 74, 75, 76, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 124, 125, 126, 127};
int myLEDs6[] = {309, 310, 311, 130, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 128, 129, 130, 131, 132};
int myLEDS7[] = {135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153};
int myLEDS8[] = {154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 191, 192, 193, 194, 195, 196, 197, 198};
int myLEDS9[] = {164, 165, 166, 167, 168, 169, 182, 183, 184, 185, 186, 187, 188, 189};
int myLEDS10[] = {170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181 };
int myLEDS11[] = {199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224};
int myLEDS12[] = {223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246};

Now I only want to build a Loop function that displays the arrays in sequence from 0 to 12. No matter what color. Any suggestion?

Thank you in advance.

[Arduino UNO]

Maybe turn those 12 arrays into a single two-dimensional. Otherwise your code will become very long and repetitive. Problem is, the arrays are not the same length, so it is not straight forward to do.

So first, let us take a step back and explain what is going on and why you need these arrays. Maybe there is a better way.

As suggested, the obvious thing to do is to put the arrays into another array thus creating a 2 dimensional array. You could solve the problem of the child arrays being of different lengths by adding a final entry to each of a value that does not occur in any of them, say -1 and declaring all of the arrays with the same number of elements as the largest. This would waste memory but that may not matter depending on your program.

By declaring the arrays like that you could pass the array number to a function and iterate through each entry in the array line and do what you need with the value until you find a -1. At that point you tidy up the display and return from the function

Details of what you are trying to do would help considerably in suggesting solutions

UPDATE :
Using pointers you don’t have to waste any memory as each child array can have a different length

Example

int a1[] = {1, 2, 3, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, -1};
int a2[] = {22, 33, -1};
int a3[] = {123, 456, 789, 135, 246, - 1};

int * b1[] = {a1, a2, a3};

void setup()
{
  Serial.begin(115200);
  for (int x = 0; x < 3; x++)
  {
    printArray(x);
  }
}

void loop()
{
}
void printArray(int arrayNum)
{
  byte index = 0;
  while (b1[arrayNum][index] != -1)
  {
    Serial.print(b1[arrayNum][index]);
    Serial.print(" ");
    index++;
  }
  Serial.println();
}

Thank you for the answers.
What we need to do for this project is setting up a station that contains boxes of different kind.
Every time we scan an item the arduino lights up the correct array of LEDs that corresponds to the correct shelf that contains the right box.

The strip of LEDs goes this way

Box7 Box6 Box5 Box4 Box1 - 3
||||________ ===========Arduino

Box8 | Box9 | Box10 | Box11 | Box12 -13

The LED strip starts with box1 and loopsafter box5 with a cut and it is connected with a 3 poles clamp again for the second row that goes from Box6 to 10.

I Some shelves use more than one box for a total of 12 different arrays. Also Some of the LEDs are unused because of the space between the shelves.

LEDs0  =  {0, 1, 2, 3, 4, 5, 6, 7, 8};     //box 1 	(Skip next 2)
LEDs1  =  {11, 12, 13, 14};	         //box 2 	(skip next 4)
LEDs2  =  {19, 20, 21, 22};		 //box 3	(Skip next 6)  //I shelf

LEDs3  =  {29, 30, 31, 32};		 //box 4	(Skip next 2)  //II shelf


LEDs4  =  {35, 36};			         //box 5	(Skip next 1)  // III shelf


LEDs5  =  {38, 39};			         //box 6	(No Skip)       // IV Shelf

LEDs6  =  {40, 41};			         //box 7	(Cut and connect with clamp) //V shelf


LEDs7  =  {42, 43};			         //box 8	(No Skip)  //VI shelf

LEDs8  =  {44, 45};			         //box 9	(Skip next 7) //VII shelf

LEDs9  =  {53, 54};			         //box 10	(Skip next 3) //VIII shelf
LEDs10 =  {58, 59, 60};			 //box 11	(Skip next 7) //IX shelf

LEDs11 =  {68, 69, 70);			 //box 12	(Skip next 5)
LEDs12 =  {76, 77, 78, 79);		 //box 13	(End of the Strip) //X shelf

Thank you again

So you are saying the led index numbers corresponding to any box are contiguous? In that case, you do not need to store each led index, only the first and last index.

#define NUMBOXES 13
byte boxFirst[NUMBOXES] = {0, 11, 19, 29, 35, 38, 40, 42, 44, 53, 58, 68, 76};
byte boxLast[NUMBOXES]  = {8, 14, 22, 32, 36, 39, 41, 43, 45, 54, 60, 70, 79};

...

void setBox(byte box, CRGB colour) {
  for (byte led = boxFirst[box]; led <= boxLast[box]; led++) leds[led] = colour;
  FastLED.show();
}

...

for (byte box = 0; box < NUMBOXES; box++) {
  setBox(box, CRGB::Red);
  delay(500);
  setBox(box, CRGB::Black);
}

Thank you. I need to try it. So in this case What I really need is the first and last LEDs to define the lenght of the shelf?

How can Assign different colors though?

komodo127:
Thank you. I need to try it. So in this case What I really need is the first and last LEDs to define the lenght of the shelf?

No, the length of each box. Why is the length of the self important?

komodo127:
How can Assign different colors though?

In several ways. You have not explained what function colour serves in your project. In fact, in the original post, you say

No matter what color.

Will the same box always be the same colour? Will colour be determined by the state of the box in some way?

Hi, thank you gain for the answer:

I had no luck using the 2 arrays. Anyway I am back on my old solution:

#include <bitswap.h>
#include <chipsets.h>
#include <color.h>
#include <colorpalettes.h>
#include <colorutils.h>
#include <controller.h>
#include <cpp_compat.h>
#include <dmx.h>
#include <fastLED.h>
#include <fastled_config.h>
#include <fastled_delay.h>
#include <fastled_progmem.h>
#include <fastpin.h>
#include <fastspi.h>
#include <fastspi_bitbang.h>
#include <fastspi_dma.h>
#include <fastspi_nop.h>
#include <fastspi_ref.h>
#include <fastspi_types.h>
#include <hsv2rgb.h>
#include <led_sysdefs.h>
#include <lib8tion.h>
#include <noise.h>
#include <pixelset.h>
#include <pixeltypes.h>
#include <platforms.h>
#include <power_mgt.h>

#include <FastLED.h>
#define LED_PIN     4
#define NUM_LEDS    80
CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  
}
void loop() {
  
  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  leds[1] = CRGB(255, 0, 0);
  FastLED.show();
  leds[2] = CRGB(255, 0, 0);
  FastLED.show();
  leds[3] = CRGB(255, 0, 0);
  FastLED.show();
  leds[4] = CRGB(255, 0, 0);
  FastLED.show();
  leds[5] = CRGB(255, 0, 0);
  FastLED.show();
  leds[6] = CRGB(255, 0, 0);
  FastLED.show();
  leds[7] = CRGB(255, 0, 0);
  FastLED.show();
  leds[8] = CRGB(255, 0, 0);  //Box1
  FastLED.show();
  delay(500);  
  leds[11] = CRGB(0, 255, 0);
  FastLED.show();
  leds[12] = CRGB(0, 255, 0);
  FastLED.show();
  leds[13] = CRGB(0, 255, 0);
  FastLED.show();
  leds[14] = CRGB(0, 255, 0); //Box2
  FastLED.show();
  delay(500);
  leds[19] = CRGB(0, 0, 255);
  FastLED.show();
  leds[20] = CRGB(0, 0, 255);
  FastLED.show();
  leds[21] = CRGB(0, 0, 255);
  FastLED.show();
  leds[22] = CRGB(0, 0, 255); //Box3
  FastLED.show();
  delay(500);
  leds[29] = CRGB(150, 60, 255);
  FastLED.show();
  leds[30] = CRGB(150, 60, 255);
  FastLED.show();
  leds[31] = CRGB(150, 60, 255);
  FastLED.show();
  leds[32] = CRGB(150, 60, 255); //Box4
  FastLED.show();
  delay(500);
  leds[35] = CRGB(255, 0, 0);
  FastLED.show();
  leds[36] = CRGB(255, 0, 0); //Box5
  FastLED.show();
  delay(500);
  leds[38] = CRGB(85, 60, 180);
  FastLED.show();
  leds[39] = CRGB(85, 60, 180); //Box6
  FastLED.show();
  delay(500);
  leds[40] = CRGB(50, 255, 20);
  FastLED.show();
  leds[41] = CRGB(50, 255, 20); //Box7
  FastLED.show();
  leds[42] = CRGB(255, 0, 0);
  FastLED.show();
  leds[43] = CRGB(255, 0, 0); //Box8
  FastLED.show();
  delay(500);  
  leds[44] = CRGB(0, 255, 0);
  FastLED.show();
  leds[45] = CRGB(0, 255, 0); //Box9
  FastLED.show();
  delay(500);
  leds[53] = CRGB(0, 0, 255);
  FastLED.show();
  leds[54] = CRGB(0, 0, 255); //Box10
  FastLED.show();
  delay(500);
  leds[58] = CRGB(150, 0, 255);
  FastLED.show();
  leds[59] = CRGB(150, 0, 255);
  FastLED.show();
  leds[60] = CRGB(150, 0, 255); //Box11
  FastLED.show();
  delay(500);
  leds[68] = CRGB(255, 200, 20);
  FastLED.show();
  leds[69] = CRGB(255, 200, 20);
  FastLED.show();
  leds[70] = CRGB(255, 200, 20); //Box12
  FastLED.show();
  delay(500);
  leds[76] = CRGB(85, 60, 180);
  FastLED.show();
  leds[77] = CRGB(85, 60, 180);
  FastLED.show();
  leds[78] = CRGB(85, 60, 180);
  FastLED.show();
  leds[79] = CRGB(85, 60, 180); //Box13
  FastLED.show();
  delay(500);
}

It is Ugly and heavy but so far it works.

My goal is to turn on ONE box at the time and for ONE box I mean the LEDs relative to that box.

So if Box1 is turned on Box{2,3,4,5,6…13} are off and than move to the next one.

After that I would like to open a connection with the serial port and try to turn on each box with inputs from my pc.

thank you again :slight_smile:

I had no luck using the 2 arrays.

Luck does not help with coding, no matter how much or how little you have.

I'm not going to help you with that huge mess of code. I suggested a better and easier way and you dismissed it. If you wanted my advice you would have posted your attempt with the two arrays and asked for assistance.

A small portion of your code

  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  leds[1] = CRGB(255, 0, 0);
  FastLED.show();
  leds[2] = CRGB(255, 0, 0);
  FastLED.show();
  leds[3] = CRGB(255, 0, 0);
  FastLED.show();
  leds[4] = CRGB(255, 0, 0);
  FastLED.show();
  leds[5] = CRGB(255, 0, 0);
  FastLED.show();
  leds[6] = CRGB(255, 0, 0);
  FastLED.show();
  leds[7] = CRGB(255, 0, 0);
  FastLED.show();

Things to note :

1 - there is a pattern to the number used as the index to the leds array, ie it goes from 0 to 7 (and higher) in steps of 1

2 - You could use a for loop to create numbers between 0 and 7 (and higher)

3 - you only need to use FastLED.show() once after all of the LEDs have been set to the required colour

PaulRB:
Luck does not help with coding, no matter how much or how little you have.

I’m not going to help you with that huge mess of code. I suggested a better and easier way and you dismissed it. If you wanted my advice you would have posted your attempt with the two arrays and asked for assistance.

Fair enough…
Tried again with the modification suggested. Unfortunately it does not work for me.
But I am going forward with this code:

#include <FastLED.h>
#include <Adafruit_NeoPixel.h>

#define NUM_LEDS 80
#define CLOCK_PIN 5
#define DATA_PIN 4
CRGB leds[NUM_LEDS];
#define COLOR_ORDER BGR
#define BRIGHTNESS  20

#define Shelves 13
byte startarr[Shelves] = {0, 11, 19, 29, 35, 38, 40, 42, 44, 53, 58, 68, 76};
byte stoparr[Shelves]  = {8, 14, 22, 32, 36, 39, 41, 43, 45, 54, 60, 70, 79};

void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  LEDS.setBrightness(BRIGHTNESS);
}

void loop(){
  if (Serial.available() >0){          
    rxChar = Serial.read();             
    Serial.flush();                   
  
  switch (rxChar) {
    
    case 'Box1':
     if (digitalRead(Shelves) == LOW){       
          digitalWrite(LED0,HIGH);      
          
 }
        else Serial.println("Shelves already On!");
 digitalWrite(Shelves,LOW);
        break;
   
 case 'Box2':
     if (digitalRead(Shelves) == LOW){       
          digitalWrite(Shelves,HIGH);      
          
 }
        else Serial.println("Shelves already On!");
 digitalWrite(Shelves,LOW);
        break;

    default:                           
      Serial.print("'");
      Serial.print((char)rxChar);
      Serial.println("' is not a command!");
    }
  }
}

Now I open the serial port and I send data with the serial port (raspberry pi) to arduino.
I’d like to turn on a specific section with a specific input from the serial port.

Es: “Box1” —> Array1

Thank you in advance

Unfortunately it does not work for me.

Why, what is different about your project which means this would not work? Or did you mean to say "I could not make it work"? I don't see the code I suggested in post #5 in your code above. What I do see is your code using "Shelves", which is the number of shelves, as an Arduino pin number.

Please always perform Auto Format before you post your code, otherwise it's quite difficult to read and understand

PaulRB:
did you mean to say "I could not make it work"?

No I mean It does not work... or at least Arduino refuses to make it work. All it does is turning on only the first leds of each array instead of having the whole array on.

Anyway I will change the code again without changing a single character from post #5 and I will let you know.

P.S. If you have a better way for me to complete this project please feel free to post it.

Thank you in advance

Also this is the link for the led strip I am using for this project.

At the end I solved it and now I have everything working with the serial and the different sections.

Was all help from this forum useless to you? If not, you should post your working code here so that others can benefit from what you learned. Also we might have suggestions for improvements. But if the forum was of no help to you, then feel free to keep the code to yourself.

I had to log out yesterday, my company is very restrictive and does not allow for overtime.

#include <bitswap.h>
#include <chipsets.h>
#include <color.h>
#include <colorpalettes.h>
#include <colorutils.h>
#include <controller.h>
#include <cpp_compat.h>
#include <dmx.h>
#include <fastLED.h>
#include <fastled_config.h>
#include <fastled_delay.h>
#include <fastled_progmem.h>
#include <fastpin.h>
#include <fastspi.h>
#include <fastspi_bitbang.h>
#include <fastspi_dma.h>
#include <fastspi_nop.h>
#include <fastspi_ref.h>
#include <fastspi_types.h>
#include <hsv2rgb.h>
#include <led_sysdefs.h>
#include <lib8tion.h>
#include <noise.h>
#include <pixelset.h>
#include <pixeltypes.h>
#include <platforms.h>
#include <power_mgt.h>

#include <FastLED.h>
#define LED_PIN     4
#define NUM_LEDS    80 
#define LED0 13          // Pin 13 is connected to the LED

char rxChar= 0;         // RXcHAR holds the received command.

CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  

  
//---------------- setup ---------------------------------------------

  Serial.begin(9600);   // Open serial port (9600 bauds).
  pinMode(LED0, OUTPUT); // Sets pin 13 as OUTPUT.
    Serial.flush();       // Clear receive buffer.
 }

//--------------- loop ----------------------------------------------- 
void loop(){
  if (Serial.available() >0){          // Check receive buffer.
    rxChar = Serial.read();            // Save character received. 
    Serial.flush();                    // Clear receive buffer.
  
  switch (rxChar) {
    
    case '1':
      if (digitalRead(leds[0]) == LOW){        // If LED is Off:
  leds[0] = CRGB(0, 255, 0);
  leds[1] = CRGB(0, 255, 0);
  leds[2] = CRGB(0, 255, 0);
  leds[3] = CRGB(0, 255, 0);
  leds[4] = CRGB(0, 255, 0);
  leds[5] = CRGB(0, 255, 0);
  leds[6] = CRGB(0, 255, 0);
  leds[7] = CRGB(0, 255, 0);
  leds[8] = CRGB(0, 255, 0);  
  FastLED.show();
  delay(4000);
  }

  leds[0] = CRGB(255, 0, 0);
  leds[1] = CRGB(255, 0, 0);
  leds[2] = CRGB(255, 0, 0);
  leds[3] = CRGB(255, 0, 0);
  leds[4] = CRGB(255, 0, 0);
  leds[5] = CRGB(255, 0, 0);
  leds[6] = CRGB(255, 0, 0);
  leds[7] = CRGB(255, 0, 0);
  leds[8] = CRGB(255, 0, 0);  
  FastLED.show();
  delay(500);
  leds[0] = CRGB(0, 0, 0);
  leds[1] = CRGB(0, 0, 0);
  leds[2] = CRGB(0, 0, 0);
  leds[3] = CRGB(0, 0, 0);
  leds[4] = CRGB(0, 0, 0);
  leds[5] = CRGB(0, 0, 0);
  leds[6] = CRGB(0, 0, 0);
  leds[7] = CRGB(0, 0, 0);
  leds[8] = CRGB(0, 0, 0);  
  FastLED.show();
  delay(500);
  break;
  
case '2':
      if (digitalRead(leds[11]) == LOW){        // If LED is Off:
    leds[11] = CRGB(0, 255, 0);
    leds[12] = CRGB(0, 255, 0);
    leds[13] = CRGB(0, 255, 0);
    leds[14] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
 }
    leds[11] = CRGB(255, 0, 0);
    leds[12] = CRGB(255, 0, 0);
    leds[13] = CRGB(255, 0, 0);
    leds[14] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[11] = CRGB(0, 0, 0);
    leds[12] = CRGB(0, 0, 0);
    leds[13] = CRGB(0, 0, 0);
    leds[14] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
        break;
    case '3':
      if (digitalRead(leds[19]) == LOW){        // If LED is Off::
    leds[19] = CRGB(0, 255, 0);
    leds[20] = CRGB(0, 255, 0);
    leds[21] = CRGB(0, 255, 0);
    leds[22] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }
    leds[19] = CRGB(255, 0, 0);
    leds[20] = CRGB(255, 0, 0);
    leds[21] = CRGB(255, 0, 0);
    leds[22] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[19] = CRGB(0, 0, 0);
    leds[20] = CRGB(0, 0, 0);
    leds[21] = CRGB(0, 0, 0);
    leds[22] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
    case '4':
if (digitalRead(leds[29]) == LOW){        // If LED is Off:
    leds[29] = CRGB(0, 255, 0);
    leds[30] = CRGB(0, 255, 0);
    leds[31] = CRGB(0, 255, 0);
    leds[32] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[29] = CRGB(255, 0, 0);
    leds[30] = CRGB(255, 0, 0);
    leds[31] = CRGB(255, 0, 0);
    leds[32] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[29] = CRGB(0, 0, 0);
    leds[30] = CRGB(0, 0, 0);
    leds[31] = CRGB(0, 0, 0);
    leds[32] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
        case '5':
      if (digitalRead(leds[35]) == LOW){        // If LED is Off:
    leds[35] = CRGB(0, 255, 0);
    leds[36] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[35] = CRGB(255, 0, 0);
    leds[36] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[35] = CRGB(0, 0, 0);
    leds[36] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
            case '6':
      if (digitalRead(leds[38]) == LOW){        // If LED is Off:
    leds[38] = CRGB(0, 255, 0);
    leds[39] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[38] = CRGB(255, 0, 0);
    leds[39] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[38] = CRGB(0, 0, 0);
    leds[39] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
        case '7':
      if (digitalRead(leds[40]) == LOW){        // If LED is Off:
    leds[40] = CRGB(0, 255, 0);
    leds[41] = CRGB(0, 255, 0);
    leds[42] = CRGB(0, 255, 0);
    leds[43] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[40] = CRGB(255, 0, 0);
    leds[41] = CRGB(255, 0, 0);
    leds[42] = CRGB(255, 0, 0);
    leds[43] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[40] = CRGB(0, 0, 0);
    leds[41] = CRGB(0, 0, 0);
    leds[42] = CRGB(0, 0, 0);
    leds[43] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
            case '8':
      if (digitalRead(leds[44]) == LOW){        // If LED is Off:
    leds[44] = CRGB(0, 255, 0);
    leds[45] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[44] = CRGB(255, 0, 0);
    leds[45] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[44] = CRGB(0, 0, 0);
    leds[45] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
            case '9':
      if (digitalRead(leds[53]) == LOW){        // If LED is Off:
    leds[53] = CRGB(0, 255, 0);
    leds[54] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[53] = CRGB(255, 0, 0);
    leds[54] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[53] = CRGB(0, 0, 0);
    leds[54] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
            case 'a':
      if (digitalRead(leds[58]) == LOW){        // If LED is Off:
    leds[58] = CRGB(0, 255, 0);
    leds[59] = CRGB(0, 255, 0); 
    leds[60] = CRGB(0, 255, 0);
    FastLED.show();
    delay(4000);
  }

    leds[58] = CRGB(255, 0, 0);
    leds[59] = CRGB(255, 0, 0); 
    leds[60] = CRGB(255, 0, 0);
    FastLED.show();
    delay(500);
    leds[58] = CRGB(0, 0, 0);
    leds[59] = CRGB(0, 0, 0); 
    leds[60] = CRGB(0, 0, 0);
    FastLED.show();
    delay(500);
    break;
                case 'b':
      if (digitalRead(leds[68]) == LOW){        // If LED is Off:
    leds[68] = CRGB(0, 255, 0);
    leds[69] = CRGB(0, 255, 0); 
    leds[70] = CRGB(0, 255, 0);
    FastLED.show();
    delay(4000);
  }

    leds[68] = CRGB(255, 0, 0);
    leds[69] = CRGB(255, 0, 0); 
    leds[70] = CRGB(255, 0, 0);
    FastLED.show();
    delay(500);
    leds[68] = CRGB(0, 0, 0);
    leds[69] = CRGB(0, 0, 0); 
    leds[70] = CRGB(0, 0, 0);
    FastLED.show();
    delay(500);
    break;
            case 'c':
      if (digitalRead(leds[76]) == LOW){        // If LED is Off:
    leds[76] = CRGB(0, 255, 0);
    leds[77] = CRGB(0, 255, 0);
    leds[78] = CRGB(0, 255, 0);
    leds[79] = CRGB(0, 255, 0); 
    FastLED.show();
    delay(4000);
  }

    leds[76] = CRGB(255, 0, 0);
    leds[77] = CRGB(255, 0, 0);
    leds[78] = CRGB(255, 0, 0);
    leds[79] = CRGB(255, 0, 0); 
    FastLED.show();
    delay(500);
    leds[76] = CRGB(0, 0, 0);
    leds[77] = CRGB(0, 0, 0);
    leds[78] = CRGB(0, 0, 0);
    leds[79] = CRGB(0, 0, 0); 
    FastLED.show();
    delay(500);
    break;
      

    }
  }
}

So now I can open the serial and allow the raspberry pi to send a character to my arduino board and having the right section turning on for 4 seconds (green) and red for 1/2 a second.

Off course it is ugly and it takes a lot of memory but so far this is the only solution that works for me.

Other improvements I’d like to see is to accept more than one character at the time with a buffer.

This is how small your sketch would be if you used functions, loos, and constants instead of repeating code over and over.

#include <FastLED.h>

const byte LED_PIN  =   4;
const byte NUM_LEDS  =  80;
const byte LED0 = 13;          // Pin 13 is connected to the LED

char rxChar = 0;        // RXcHAR holds the received command.

const CRGB CRGBBlack = CRGB(0, 0, 0);
const CRGB CRGBGreen = CRGB(0, 255, 0);
const CRGB CRGBRed = CRGB(255, 0, 0);

CRGB leds[NUM_LEDS];

//---------------- setup ---------------------------------------------
void setup()
{
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

  Serial.begin(9600);   // Open serial port (9600 bauds).
  pinMode(LED0, OUTPUT); // Sets pin 13 as OUTPUT.
  Serial.flush();       // Wait for output buffer to empty
}


void SetLEDGroup(byte startIndex, byte endIndex, CRGB color)
{
  for (byte i = startIndex; i <= endIndex; i++)
    leds[i] = color;
  FastLED.show();
}

void DisplayLEDGroup(byte startIndex, byte endIndex)
{
  if (leds[startIndex] == CRGBBlack)
  {
    SetLEDGroup(startIndex, endIndex, CRGBGreen);
    delay(4000);
  }
  SetLEDGroup(startIndex, endIndex, CRGBRed);
  delay(500);

  SetLEDGroup(startIndex, endIndex, CRGBBlack);
}

//--------------- loop -----------------------------------------------
void loop()
{
  if (Serial.available() > 0)          // Check receive buffer.
  {
    rxChar = Serial.read();            // Save character received.
    Serial.flush();                    // Wait for output buffer to empty

    switch (rxChar)
    {
      case '1':  DisplayLEDGroup(0, 8); break;

      case '2':  DisplayLEDGroup(11, 14); break;

      case '3':  DisplayLEDGroup(19, 22); break;

      case '4':  DisplayLEDGroup(29, 32); break;

      case '5':  DisplayLEDGroup(35, 36); break;

      case '6':  DisplayLEDGroup(38, 39); break;

      case '7':  DisplayLEDGroup(40, 43); break;

      case '8':  DisplayLEDGroup(44, 45); break;

      case '9':  DisplayLEDGroup(53, 54); break;

      case 'a':   DisplayLEDGroup(58, 60); break;

      case 'b':  DisplayLEDGroup(68, 70); break;

      case 'c':   DisplayLEDGroup(76, 79); break;

    }
  }
}

That is awesome, I wish I had the skills for that. I am relatively new to Arduino and I am moving my steps while having to deal with my bosses always involved with projects.

I will try to fix it as soon as possible.

Thank you again for this :smiley: