Issues with "states" simulating rear car lights

Hi everyone! This is my first posting here so I apologize is I humble a little.

Currently, I am using two DotStar 8x8 LED matrix to simulate car lights; however, I am running into the issue where, regardless of my serial input, the LEDs are set on the brake and left turn lights on. When other relevant inputs are entered into the serial input terminal the lights all flicker -i.e between the brake and turn lights- and then turn back to the brake and left turn lights.

Ideally, I would like to be able to enter the character into the serial input terminal have the expected outcome as shown in the code below.

Thank you for your assistance in advance!

#include <Adafruit_DotStarMatrix.h> //dotstar matrix
#include <gamma.h> //part of dotstar matrix
#include <Adafruit_GFX.h> //GFX
#include <Adafruit_SPITFT.h> //part of GFX
#include <Adafruit_SPITFT_Macros.h> //part of GFx
#include <gfxfont.h> //part of GFX
#include <Arduino.h>
#include <Adafruit_DotStar.h>
#include <SPI.h>         


#define NUMPIXELS 128 // Number of LEDs in strip
#define DATAPIN    4
#define CLOCKPIN   5
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

void setup() 
{
  Serial.begin(9600);           // Initialize serial input 
  strip.begin();                    // Initialize pins for output
  strip.show();                    // Update LEDs
}


char light = 0;
uint32_t brake = strip.Color(0,20,0); // Green, red, blue
uint32_t turn = strip.Color(5, 15,0);

void loop() 
{
  if(Serial.available() > 0)
  {
    light = Serial.read();

    if(light = '1')            //Brakes
    {
      strip.fill(0,0,128);
      strip.show();
      strip.fill(brake,0,32);
      strip.fill(brake,96,32);
      strip.show();
    }

    if(light = '2')           //No lights
    {
      strip.fill(0,0,128);
      strip.show();
    }

    if(light = '3')           //Turn left
    {
      strip.fill(0,0,128);
      strip.show();
      strip.fill(turn,32,32);
      strip.show();
    }

    if(light = '4')            //Turn right
    {
      strip.fill(0,0,128);
      strip.show();
      strip.fill(turn,64,32);
      strip.show();
    }

    if(light = '5')            //Brake and turn left
    {
      strip.fill(0,0,128);
      strip.show();
      strip.fill(brake,0,32);
      strip.fill(brake,96,32);
      strip.fill(turn,32,32);
      strip.show();
    }

    if(light = '6')            //Brake and turn right
    {
      strip.fill(0,0,128);
      strip.show();
      strip.fill(brake,0,32);
      strip.fill(brake,96,32);
      strip.fill(turn,64,32);
      strip.show();
    }
  }
}

I was able to find the answer!!

After inserting “Serial.println(light);” into each of the states, I was able to find that I was redefining the value of char light because I had written:

if(light = ‘(some number 1-6)’)

To correctly check the state, I needed to have the logical operator “==” instead.

shinobirain:
I was able to find the answer!!

After inserting "Serial.println(light);" into each of the states, I was able to find that I was redefining the value of char light because I had written:

if(light = '(some number 1-6)')

To correctly check the state, I needed to have the logical operator "==" instead.

Nice work in finding your issue. That type of bug can be very hard to find. I recently at work had to fix am application that was crashing. I found the same type of logic bomb you did. Took me 2 days to find it, in about 300,000 lines of code.

So again, good job spotting it.

Now, if the future, you can avoid this type of mistake.

for example
if(something == true)

can be changed to
if(true == something)

If you do your checks like this, you will never be able to accedently assign when you ment to compare.

To have to go through 300k lines of code and fine such a fine detail is definitely nothing short of high concentration.

I did not know that that it was possible to change the order of the if ((something) == (something else));
thank you for sharing a little bit of knowledge and a coding story as well!