Integrated Motorcycle Taillight

Right now, I have 3 WS2812b LEDs setup on a breadboard, but the finished project will have 40 (2 stacked rows of 20).
LED 0 is the left indicator, LED 2 is the right indicator, and all three are brake and parking.
I need to have all the LEDs on when the bike is turned on.
I need to have them all lit brightly when the connection on either brake switch is completed.
When the left indicator is needed, the left 20 LEDs (top and bottom rows) will flash from either dim or bright red (depending on if the brake or parking light is on) to bright amber.
The opposite for the right indicator.

I already have the parking and brake lights working. I’m having issues with the indicators.
When using the left indicator, LED 0 flashes from amber to red but LED 1 and 2 flash from dim to bright red also. It’s the same when using the right indicator (LED2). If the brake light is on when using the left indicator, then LED 0 flashes from dim red to bright amber and the other 2 LEDs stay bright red.

What I’d like to happen with the indicators, is to switch from bright amber to off, regardless if the brake or parking light is on… Eventually, I want to add something that would cycle them from from the center to the edge (sequential), but I’m just setting to get the behavior I mention above right now.

I’ve pieced together this much so far. I’m not sure if this is compact, but it’s working for the most part.

#include <Adafruit_NeoPixel.h>

    int buttonPin0 = 0;    // push button on pin 0 - Left Blinker and Brake and Parking
    int buttonPin1 = 1;    //  push button on pin 1 - Brake and parking
    int buttonPin2 = 2;    //  push button on pin 2 - Right Blinker and Brake and Parking
    int oldButtonVal = 0;
    
    #define PIN 6 
    
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_GRB + NEO_KHZ800);

// the setup routine runs once when you press reset:
    void setup() {
    strip.begin();
    strip.show();           // initialize all pixels to 'off'    
// initialize the BUTTON pin as an input
    pinMode(buttonPin0, INPUT);
    digitalWrite(buttonPin0, LOW);  // button pin is HIGH, so it drops to 0 if pressed
    pinMode(buttonPin1, INPUT);
    digitalWrite(buttonPin1, LOW);  // button pin is HIGH, so it drops to 0 if pressed
    pinMode(buttonPin2, INPUT);
    digitalWrite(buttonPin2, LOW);  // button pin is HIGH, so it drops to 0 if pressed
}

void loop() {
  int buttonVal = digitalRead(buttonPin0); Left Blinker and Brake/Parking
  int buttonVal1 = digitalRead(buttonPin1);Brake/Parking
  int buttonVal2 = digitalRead(buttonPin2);Right Blinker and Brake/Parking
  
  if 
      (buttonVal == LOW) // && buttonVal1 == HIGH) 
       { // button has just been pressed
        strip.setPixelColor(0, strip.Color(255, 0, 0)); // Brake Light
        strip.setPixelColor(1, strip.Color(255, 0, 0));
        strip.setPixelColor(2, strip.Color(255, 0, 0));
        strip.setBrightness(255);
        strip.show();
} else {
        strip.setPixelColor(0, strip.Color(255, 0, 0)); // Parking Light
        strip.setPixelColor(1, strip.Color(255, 0, 0));
        strip.setPixelColor(2, strip.Color(255, 0, 0));
        strip.setBrightness(30);
        strip.show(); 
}
  if 
      (buttonVal1 == HIGH) 
       { // && oldButtonVal == LOW) { // button has just been pressed
        strip.setPixelColor(2, strip.Color(255, 128, 0)); // Right Blinker
        strip.setBrightness(255);
        delay(500);
        strip.show();
        strip.setPixelColor(2, strip.Color(0, 0, 0));
        strip.setBrightness(255);
        delay(500);
    strip.show();
}
  if 
      (buttonVal2 == HIGH) {// button has just been pressed
        strip.setPixelColor(0, strip.Color(255, 128, 0)); // Left Blinker
        strip.setBrightness(255);
        delay(500);
        strip.show();
        strip.setPixelColor(0, strip.Color(0, 0, 0));
        strip.setBrightness(255);
        delay(500);
    strip.show();
  }
}

I’d also like to add that this is my first jump into coding. If you see anything weird, it’s because I’m new and don’t have any structure.

Any help is greatly appreciated

If you initialize a pin as input, you can't turn around and write to it.

You will need to debounce the pushbutton switches.

The code in the loop( ) function runs very quickly.
If you are only doing a momentary button press, you probably won't see the LEDs change.

    int buttonPin0 = 0;    // momentary push button on pin 0
    int buttonPin1 = 1;    // monentary push button on pin 1

You should get your switches off the hardware serial pins, so you can debug your code.

The variables can be byte, because there are NOT that many pins.

The variables should be const, because it does not make sense to (be able to) change them.

    #define PIN 6

You should use ONE style to define pin numbers.

    void setup() {
    strip.begin();
    strip.show();           // initialize all pixels to 'off'

Your indenting sucks. Use Tools + Auto Format.

  if 
      (buttonVal == LOW) // && buttonVal1 == HIGH)

Why
is
the
if
on
one
line
with
the
rest
of
the
statement
on
another?

  int buttonVal = digitalRead(buttonPin0);
  int buttonVal1 = digitalRead(buttonPin1);
  int buttonVal2 = digitalRead(buttonPin2);

Meaningful names for the states and the pin numbers are useful. Random crap is not. Why should we have to guess which is the brake light switch, which is the left turn switch, and which is the right turn switch?

ieee488:
If you initialize a pin as input, you can't turn around and write to it.

You will need to debounce the pushbutton switches.

The code in the loop( ) function runs very quickly.
If you are only doing a momentary button press, you probably won't see the LEDs change.

They change and run until my finger is off the button.

PaulS:

    int buttonPin0 = 0;    // momentary push button on pin 0

int buttonPin1 = 1;    // monentary push button on pin 1



You should get your switches off the hardware serial pins, so you can debug your code.

The variables can be byte, because there are NOT that many pins.

The variables should be const, because it does not make sense to (be able to) change them.




#define PIN 6



You should use ONE style to define pin numbers.

Which pins are more useful for this sort of thing?
And is there a difference between one style of define or another? Any advantages or disadvantages?

PaulS:

    void setup() {

strip.begin();
    strip.show();          // initialize all pixels to 'off'



Your indenting sucks. Use Tools + Auto Format.

Still learning, but I'll take that into consideration.

PaulS:

  if 

(buttonVal == LOW) // && buttonVal1 == HIGH)



Why
is
the
if
on
one
line
with
the
rest
of
the
statement
on
another?

No idea, but as I said, this is my first jump into this kind of thing.

PaulS:

  int buttonVal = digitalRead(buttonPin0);

int buttonVal1 = digitalRead(buttonPin1);
  int buttonVal2 = digitalRead(buttonPin2);



Meaningful names for the states and the pin numbers are useful. Random crap is not. Why should we have to guess which is the brake light switch, which is the left turn switch, and which is the right turn switch?

They were listed in my description and in another part of the code, but I can see how that's needed.
Fixed.