Remembering a colour Hey guys I have a led grid. it's 8 sides that are addressable with the bytes '1' through '8'. (a Kinect is sending these bytes through processing)  I have also creates three buttons in processing that change the colour of the leds. ('R','G','B'). 

I'm stuck in the code, my code now when receiving the bytes: 'R', 'G' or 'B' changes all leds to that colour. instead of remembering the colour and only lighting up the sides determined by the '1', '2', '3', '4', '5', '6', '7', '8' values. 

I need it to remember the chosen R,G,B colour until another colour is chosen and only  use the bytes '1', '2', '3', '4', '5', '6', '7', '8' to select what side of the grid to light up. 

Here is my code so far: 


#include &lt;FastLED.h&gt;

#define LED_PIN     6
#define NUM_LEDS    360

CRGB leds[NUM_LEDS];
CRGB saved_color;

void setup()
{
  FastLED.addLeds&lt;WS2812, LED_PIN, GRB&gt;(leds, NUM_LEDS);
  FastLED.setBrightness(50);

  Serial.begin(9600);

  FastLED.clear();
  FastLED.show();

}

void loop()
{

  if (Serial.available() &gt; 1)
  {
    int incomingByte = Serial.read();

    if (incomingByte &gt; '0' &amp;&amp; incomingByte &lt; '9')
    {
      FastLED.clear();
    }


    if (incomingByte == 'R') {
      saved_color = CRGB(255, 0, 0);
    }
    else if (incomingByte == 'G') {
      saved_color = CRGB(0, 255, 0);
    }
    else if (incomingByte == 'B') {
      saved_color = CRGB(0, 0, 255);

    }

    if (incomingByte == '1')
      for (int i = 0; i &lt;= 44; i++) {
        leds[i] = saved_color;
      }

    else if (incomingByte == '2')
      for (int i = 44; i &lt;= 89; i++) {
        leds[i] = saved_color;
      }
    else if (incomingByte == '3')
      for (int i = 90; i &lt;= 134; i++) {
        leds[i] = saved_color;
      }

    else if (incomingByte == '4')
      for (int i = 135; i &lt;= 179; i++) {
        leds[i] = saved_color;
      }
    else if (incomingByte == '5')
      for (int i = 180; i &lt;= 224; i++) {
        leds[i] = saved_color;
      }
    else if (incomingByte == '6')
      for (int i = 225; i &lt;= 269; i++) {
        leds[i] = saved_color;
      }
    else if (incomingByte == '7')
      for (int i = 270; i &lt;= 314; i++) {
        leds[i] = saved_color;
      }
    else if (incomingByte == '8')
      for (int i = 315; i &lt;= 359; i++) {
        leds[i] = saved_color;

      }

    FastLED.show();
  }
}




I'll describe the project a bit more to elaborate. It's a lamp (octagon shape) with 45 leds on the 8 sides. each side is triggered by movement and  sends a byte ('1', '2', '3', '4', '5', '6', '7', '8') to turn on one side of the lamp. 

I want to be able to select the colour before sending the bytes. so I need arduino to remember the 'R', 'G', 'B' bytes and only change when I send the other byte.
The array CRGB leds[NUM_LEDS] only holds the current state of the LEDs. It is used to push the data out to the LEDs. If you want the code to save one color to use later, you need an extra variable, that can hold the color.

Add a variable at global scope:

CRGB saved_color;


In the if statements for R, G and B you can set this variable to the corresponding value, for example:

if(incomingByte == 'R'){
    saved_color = CRGB(255,0,0);
}


And in the if statements of 1 to 8 you can use this value, for example:

if (incomingByte == '1'){
    for (int i = 0; i &lt;= 44; i++) {
        leds[i] = saved_color;
    }
}


Note: The above code does not change any LEDs on R, G or B. They just set the color for future operation 1 to 8.