Needing assistance for programming turn signals

Hello, I want to make turn signals in combination with a rear light for a project I'm doing. It consists of 5 different LED's and 3 different switches. (see image)

I have 3 input pins:
1 switch to control the left led (T1)
1 switch to control the right led (T2)
1 switch to control the rear light (R, Rx1, Rx2)

I have 4 output pins; 1 for left, 1 for right, 1 for the middle red LED (R) and 1 for the 2 bottom LED's (Rx1, Rx2).

I would like to achieve the following:
When pressing the switch for the left led (T1), T1 will start to blink with a frequency of 90 blinks per minute. When pressing the switch again it will turn off. When the switched is not pressed the second time it will automatically turn off after 15 seconds. (when the button is pressed again, the same cycle will have to start over)
The same applies to the right led (T2 and it's switch) It should not be possible to have T1 and T2 blink at the same time (unless an element can be implemented where they will blink simultaneously when both switches are pressed at the same time.) .
When pressing the switch for the rear light, R, Rx1 and Rx2 need to be turned on (not blinking) but when it is on and one of the turn signals (T1 or T2) is switched on, Rx1 and Rx2 need to be switched off. When therear light button is pressed for the second time all red LED's need to be switched off.

I have already manage to have T1 blink when the button is pressed and turn off when teh button is pressed again. (using buttonstate and millis) but I don't seem to be succesful in adding the 15 seconds timer to turn it off without the switch.

Can anyone help me achieve my goal?

Thanks in advance!

This thread should help you a great deal

http://forum.arduino.cc/index.php?topic=171840.0

Mark

The IDE has many wonderful examples to get you started. I'd recommend blink without delay, and anything with buttons and debouncing.

You'll tend to find that in the programming section of this forum you won't get much help unless you actually try to do some code yourself and post it. It comes down to "what have you tried".

Post your code.

Ok I now have 2 separate codes that are not complete yet, but I don't really know how to combine them so that they will work together properly.

I have the following code to turn the red LED's on and off:

const int buttonPinR = 5;
const int ledPinR = 12;
const int ledPinRx = 11;

int ledStatus = false;
int buttonState = 0;
int lastButtonState = 0;
int lastButtonState2 = LOW;
int reading;

long lastDebounceTime = 0;
long debounceDelay = 200;

void setup() {
pinMode(buttonPinR, INPUT);
pinMode(ledPinR, OUTPUT);
pinMode(ledPinRx, OUTPUT);
}
void loop()
{

reading = digitalRead(buttonPinR);
if (reading != lastButtonState2) {
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {

buttonState = reading;
}
lastButtonState2 = reading;
if (buttonState != lastButtonState) {

if (buttonState == LOW) {
ledStatus = !ledStatus;
}

lastButtonState = buttonState;
}

if (ledStatus) {
digitalWrite(ledPinR, HIGH);
digitalWrite(ledPinRx, HIGH);
} else {
digitalWrite(ledPinR, LOW);
digitalWrite(ledPinRx, LOW);
}

}

For the left turn signal I have now:

#define ledPinLeft 10
#define buttonPinLeft 4

int value = LOW;
int buttonStateLeft;
int lastButtonStateLeft;
int blinking;
long interval = 666;
long previousMillis = 0;
long startTime ;
long elapsedTime ;
int fractional;

void setup()
{
Serial.begin(9600);

pinMode(ledPinLeft, OUTPUT);
pinMode(buttonPinLeft, INPUT);
digitalWrite(buttonPinLeft, HIGH);
}

void loop()
{
// check for button press
buttonStateLeft = digitalRead(buttonPinLeft); // read the button state and store

if (buttonStateLeft == LOW && lastButtonStateLeft == HIGH && blinking == false){

startTime = millis();
blinking = true;
delay(5);
lastButtonStateLeft = buttonStateLeft;
}

else if (buttonStateLeft == LOW && lastButtonStateLeft == HIGH && blinking == true){

elapsedTime = millis() - startTime;
blinking = false;
lastButtonStateLeft = buttonStateLeft;
}

else{
lastButtonStateLeft = buttonStateLeft;
}

if ( (millis() - previousMillis > interval) ) {

if (blinking == true){
previousMillis = millis();

if (value == LOW)
value = HIGH;
else
value = LOW;
digitalWrite(ledPinLeft, value);
}
else{
digitalWrite(ledPinLeft, LOW);
}
}

}

To this code I still need to add a timer that will also turn it off in 15 seconds.
I want to do the sam for the right side but I'm not sure how to combine the codes so it will all work at the same time.
Also I still need to add the debounce function to theis code and I'm not sure how to implement it.

So I want to combine this code with the same code for the right side and the LED's in the middle so that Rx will not burn when either turn signal is on.
So, how do I combine these things to one code that does everything?

Thanks in advance!

So, how do I combine these things to one code that does everything?

The first
thing you need
to do is use
Tools + Auto Format
to fix that horrid
indenting.

The second thing you need to do is to define the requirements for the combined program.

The third thing you need to do is pick parts of each program that implement those requirements and copy and paste them into the new program.

If the result is less than satisfactory, let us know what the requirements are, what actually happens, and how that differs from what you want.

The fourth thing you need to learn how to do is to post code correctly. Read the sticky at the top of the forum (which you should have done before posting in the first place).

So I've come a long way. I made a code for everything except the blinking and the timer. So in my code the LED_right an LED_Left will not blink when activated, but that's what I'm striving for. I've looked at Blinking without delay, but I'm not really sure how to implement this in my code for LED_right and LED_left. Can anyone help me with this?
Thanks in advance!

Here is my code so far:

//LED's
const int LED_left = 12;              // T1 in image
const int LED_right = 11;            // T2 in image
const int LED_back = 10;            // R in image
const int LED_side = 9;              // Rx1 and Rx2 in image

// Buttons
const int button_on = 2;        
const int button_left = 3;
const int button_right = 4;

//Buttonstate waarden
int buttonstate_on;
int buttonstate_left;
int buttonstate_right;
int lastbuttonstate_on;
int lastbuttonstate_left;
int lastbuttonstate_right;

// LED states
int LED_left_state = LOW;
int LED_right_state = LOW;
int LED_back_state = LOW;
int LED_side_state = LOW;

void setup() {

  Serial.begin(9600);

  pinMode(button_on, INPUT); 
  pinMode(LED_left, OUTPUT);   
  pinMode(button_left, INPUT);
  pinMode(LED_right, OUTPUT);
  pinMode(button_right, INPUT);
  pinMode(LED_back, OUTPUT);
  pinMode(LED_side, OUTPUT);

  digitalWrite(button_left, LOW);
  digitalWrite(button_right, LOW);  
}


void loop(){
  buttonstate_on = digitalRead(button_on);
  buttonstate_left = digitalRead(button_left);
  buttonstate_right = digitalRead(button_right);

  if (buttonstate_left != lastbuttonstate_left && buttonstate_left == HIGH){     
    function_left();
  }

  if (buttonstate_right != lastbuttonstate_right && buttonstate_right == HIGH){     
    function_right();
  }

  if (buttonstate_on != lastbuttonstate_on && buttonstate_on == HIGH){
    function_on();
  }
  lastbuttonstate_on = buttonstate_on; 
  lastbuttonstate_left = buttonstate_left; 
  lastbuttonstate_right = buttonstate_right; 

}

void function_left(){
  if (LED_side_state == HIGH){
    digitalWrite(LED_side, LOW);
    LED_side_state == LOW;
  }
  if(LED_right_state == HIGH){
    digitalWrite(LED_right, LOW);
    lastbuttonstate_right = LOW;
  }
  if(LED_left_state == LOW){
    digitalWrite(LED_left,HIGH);
    LED_left_state = HIGH;
  }
  else
  {
    digitalWrite(LED_left,LOW);
    LED_left_state = LOW;
    if (LED_back_state == HIGH){
      digitalWrite(LED_side,HIGH);
      LED_side_state = HIGH;
    }
    else {
      digitalWrite (LED_right,LOW);
      LED_right_state = LOW;
    }
  }        
}

void function_right(){
  if (LED_side_state == HIGH){
    digitalWrite(LED_side, LOW);
    LED_side_state == LOW;
  }
  if(LED_left_state == HIGH){
    digitalWrite(LED_left, LOW);
    lastbuttonstate_left = LOW;
  }
  if(LED_right_state == LOW){
    digitalWrite(LED_right,HIGH);
    LED_right_state = HIGH;
  }
  else {
    digitalWrite(LED_right,LOW);
    LED_right_state = LOW;
    if (LED_back_state == HIGH){
      digitalWrite(LED_side,HIGH);
      LED_side_state = HIGH;
    }
    else {
      digitalWrite (LED_right,LOW);
      LED_right_state = LOW;
    }
  }        
}


void function_on(){

  if (LED_back_state == LOW)
  {
    digitalWrite(LED_back, HIGH);
    LED_back_state = HIGH;
    digitalWrite(LED_side, HIGH);
    LED_side_state = HIGH;
  }
  else
  {
    digitalWrite(LED_back, LOW);
    LED_back_state = LOW;
    digitalWrite(LED_side, LOW);
    LED_side_state = LOW;
  }
  Serial.println(LED_back_state);

}

Adding function_ to the name of all functions makes as much sense as adding variable_ to the name of all variables.

A function name should CLEARLY define what the function does. For example, pinMode(), digitalRead(), analogWrite(), etc. do not require consulting the documentation to determine what they do.

right(), left(), and on() tell us nothing.

Nowhere are you turning pins on and off on a repeating basis.

You need some boolean variables, leftFlashing, rightFlashing, etc. Set the variable to true if the left LED should be flashing. Set it to false if not.

Then, in right(), test that variable. If it's false, return. If it's true, compare now (from millis()) to then (from millis() the last time the state of the left LED was changed). If it is time to change the state, do so, apply the new state to the pin, and reset the last-time-something-happened variable to now (from millis()).

Do the same in left().

It's not clear what on() should do.