Mustang sequential tail lights

Hi I’m new to arduino and I need some help the this code. I’m trying to program an arduino uno so it

controls 6 “TIP31C” transistors which will each control one bulb. The left and right blinkers work fine on

their own. When I try to send a “HIGH” input to both Rblinker and Lblinker at the same time (simulating

4-way flashers ) problems start to happen, the results are not as consistent as I would like. The lights

are supposed to blink in the order marked in red when alone and in blue when used as 4-way blinkers

then stay lit until the input goes “LOW” in both cases. The orders are marked in the attachment ,blue

happens at the same time for each light and red happens alone for each light. If

anyone could help me achieve more reliability and/or debug my code it would be of great help .

const int Lblinker = 5;  
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4;

const int Rblinker = 6;
const int ledPin4 = 7;
const int ledPin5 = 8;
const int ledPin6 = 9;




int buttonState1 = 0;
int buttonState2 = 0;



void setup() {
  
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);

  
  

  pinMode(Lblinker, INPUT);
  pinMode(Rblinker, INPUT);

}

void loop() {

  buttonState1 = digitalRead(Lblinker);


 
  if (buttonState1 == HIGH && buttonState2 == LOW) {
   
    digitalWrite(ledPin1, HIGH);
    delay(100);
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    delay(400);
    
    
  }
     else {
   
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
   
 
 
 
  
  buttonState2 = digitalRead(Rblinker);



  if (buttonState2 == HIGH && buttonState1 == LOW) {
   
    digitalWrite(ledPin4, HIGH);
    delay(100);
    digitalWrite(ledPin5, HIGH);
    delay(100);
    digitalWrite(ledPin6, HIGH);
    delay(400);
    
   
  } 
    else {
   
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);
 

 
  
     if(digitalRead(6) == HIGH  && digitalRead(5) == HIGH)
     {

    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin4, HIGH);
    delay(100);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin5, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin6, HIGH);
    delay(400);
    
  
    }
  
 
 }}}

any time you see this }}} you know that the {} are all messed up

try this (notes in program)

const int Lblinker = 5;
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4;

const int Rblinker = 6;
const int ledPin4 = 7;
const int ledPin5 = 8;
const int ledPin6 = 9;




int buttonState1 = 0;
int buttonState2 = 0;



void setup() {

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);




  pinMode(Lblinker, INPUT);
  pinMode(Rblinker, INPUT);

}

void loop() {

  buttonState1 = digitalRead(Lblinker);
  buttonState2 = digitalRead(Rblinker);//moved to here


  if (buttonState1 == HIGH && buttonState2 == LOW) {

    digitalWrite(ledPin1, HIGH);
    delay(100);
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    delay(400);


  }
  else {

    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
  }//added


  if (buttonState2 == HIGH && buttonState1 == LOW) {

    digitalWrite(ledPin4, HIGH);
    delay(100);
    digitalWrite(ledPin5, HIGH);
    delay(100);
    digitalWrite(ledPin6, HIGH);
    delay(400);


  }
  else {

    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
    digitalWrite(ledPin6, LOW);

  } //added


  if (digitalRead(6) == HIGH  && digitalRead(5) == HIGH)
  {

    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin4, HIGH);
    delay(100);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin5, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin6, HIGH);
    delay(400);


  }

//removed 2 close switchs from here
}

thanks gpop1 that solved part of the problem. Now the issue I’m having is that the “4-way flasher” part of the

code is constantly repeating and should stay on until the input goes “LOW”.

So if you press both butons, you get a hazard pattern, and the hazard pattern stays on for so long as either button is pressed. Remember that with INPUT_PULLUP, HIGH is off and LOW is on.

This would be better with a "blink without delay" mechanism, but it should be ok for what you want.

(I am not on a machine with the arduino IDE at the moment, so this code may not compile)

enum Pattern {
  off = 0,
  left = 1,
  right = 2,
  hazard = 3;
};


Pattern currentState = off;

void loop() {
 
  // "true" means "the blinker switch is pressed"
  boolean leftBlinker = /* read the left blinker switch */;
  boolean rightBlinker = /* read the right blinker switch */;

  if(leftBlinker && rightBlinker) {
    currentState = hazard;
  }
  else if(!leftBlinker && !rightBlinker) {
    currentState = off;
  }
  // at this point, one of the switches is on and one is off
  else if(leftBlinker && currentState != hazard) {
    currentState = left;
  }
  else if(rightBlinker && currentState != hazard){
    currentState = right;
  }
  else {
    // only way to get here is to have one switch down but we are
    // in hazard mode
    ; // do nothing
  }


  switch(currentState) {
  case off: break;
  case left: 
    // left blink sequence;
    break;
  case right: 
    // right blink sequence;
    break;
  case hazard: 
    // hazard blink sequence;
    break;
  }

}

what would I put in /* read the left blinker switch / and the / read the left blinker switch */ ?

PaulMurrayCbr:
So if you press both butons, you get a hazard pattern, and the hazard pattern stays on for so long as either button is pressed. Remember that with INPUT_PULLUP, HIGH is off and LOW is on.

This would be better with a “blink without delay” mechanism, but it should be ok for what you want.

(I am not on a machine with the arduino IDE at the moment, so this code may not compile)

enum Pattern {

off = 0,
 left = 1,
 right = 2,
 hazard = 3;
};

Pattern currentState = off;

void loop() {

// “true” means “the blinker switch is pressed”
 boolean leftBlinker = /* read the left blinker switch /;
 boolean rightBlinker = /
read the right blinker switch */;

if(leftBlinker && rightBlinker) {
   currentState = hazard;
 }
 else if(!leftBlinker && !rightBlinker) {
   currentState = off;
 }
 // at this point, one of the switches is on and one is off
 else if(leftBlinker && currentState != hazard) {
   currentState = left;
 }
 else if(rightBlinker && currentState != hazard){
   currentState = right;
 }
 else {
   // only way to get here is to have one switch down but we are
   // in hazard mode
   ; // do nothing
 }

switch(currentState) {
 case off: break;
 case left:
   // left blink sequence;
   break;
 case right:
   // right blink sequence;
   break;
 case hazard:
   // hazard blink sequence;
   break;
 }

}

Jeff_96:
thanks gpop1 that solved part of the problem. Now the issue I'm having is that the "4-way flasher" part of the

code is constantly repeating and should stay on until the input goes "LOW".

Im really sure what you mean but im guessing that when both buttons are high you wanted the leds to stay on.

The problem is you used "else" after the "ifs"

if the "if" fails then it runs the code In the "else" so

if (buttonState1 == HIGH && buttonState2 == LOW) //fails when both buttons are high and turns the leds off

Jeff_96:
what would I put in /* read the left blinker switch / and the / read the left blinker switch */ ?

digitalread (after you have set up pin mode) you will also have to add setup() and remove the extra ; on line 5

This is where I'm at right now. I'm not to sure what to declare "currentState" as. Progress is slowly being made and I greatly appreciate all the help I'm getting.

const int Lblinker = 5;
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4;

const int Rblinker = 6;
const int ledPin4 = 7;
const int ledPin5 = 8;
const int ledPin6 = 9;

int buttonState1 = 0;
int buttonState2 = 0;


void setup (){ 
  
enum Pattern {
  off = 0,
  left = 1,
  right = 2,
  hazard = 3};



Pattern currentState = off;
}
void loop() {

  buttonState1 = digitalRead(Lblinker);
  buttonState2 = digitalRead(Rblinker); 
  
  // "true" means "the blinker switch is pressed"
  boolean leftBlinker = digitalRead(Lblinker);
  boolean rightBlinker = digitalRead(Rblinker) ;

  if(leftBlinker && rightBlinker) {
    currentState = hazard;
  }
  else if(!leftBlinker && !rightBlinker) {
    currentState = off;
  }
  // at this point, one of the switches is on and one is off
  else if(leftBlinker && currentState != hazard) {
    currentState = left;
  }
  else if(rightBlinker && currentState != hazard){
    currentState = right;
  }
  else {
    // only way to get here is to have one switch down but we are
    // in hazard mode
    ; // do nothing
  }


  switch(currentState) {
  case off: break;
  case left: 
    {
    digitalWrite(ledPin1, HIGH);
    delay(100);
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    }
    
    break;
  case right: 
    {
    digitalWrite(ledPin4, HIGH);
    delay(100);
    digitalWrite(ledPin5, HIGH);
    delay(100);
    digitalWrite(ledPin6, HIGH);
    }
  
    break;
  case hazard: 
    {
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin4, HIGH);
    delay(100);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin5, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin6, HIGH);
    }
    
    break;
  }

}