Go Down

Topic: Cornering fog lights / turning assistant. (Read 681 times) previous topic - next topic

Hants

May 14, 2013, 04:18 pm Last Edit: May 14, 2013, 04:19 pm by Hants Reason: 1
Can somebody help me to add another functionality to the code?
I would like to add an another / INT / and if there is a 5V /HIGH/  - both foglamps should go on.

Code: [Select]
/* Light turning assistant for cars (cornering lights)
  Credits to user Dr_P at http://mjlorton.com forum
 
*/


int fogL = 8;                               // 55W Relay for L fog lamp
int fogR = 7;                               // 55W Relay for R fog lamp
int indL = 4;                               // Circuit between multiswitch and indicator relay
int indR = 2;                               // Circuit between multiswitch and indicator relay




void setup()
{
pinMode(fogL, OUTPUT);
pinMode(fogR, OUTPUT);
pinMode(indL, INPUT);
pinMode(indR, INPUT);
}

void loop()

{

     {
    int i=100;                                    // counter initialized with "done" value
    if(digitalRead(indR))                  
           {
           i=0;                                   //if indicators were reversed, the cycle needs to be reset to full 5s
           while(digitalRead(indR) && i<100)
                 {
                 i++;
                 digitalWrite(fogR, HIGH);
                 digitalWrite(fogL, LOW);
                 delay(50);
                 }
           }
     if(digitalRead(indL))                        //same as right side
           {
           i=0;
           while(digitalRead(indL) && i<100)
                 {
                 i++;
                 digitalWrite(fogR, LOW);
                 digitalWrite(fogL, HIGH);
                 delay(50);
                 }
           }
     if(!digitalRead(indR) && !digitalRead(indL))      // no indicators currently on
           if(i==100)                                  //neither indicators were on OR the 5s cycle is over
                 {
                 digitalWrite(fogR, LOW);
                 digitalWrite(fogL, LOW);
                 }
           else                                        //one or both indicators were on for less than 5s
                 while(!digitalRead(indR) && !digitalRead(indL) && i<100)      //but not any more
                       {
                       i++;                           //finish the 5s cycle in the last foglight configuration
                       delay(50);
                       }
     }
}

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

JimEli

like this?
Code: [Select]

/* Light turning assistant for cars (cornering lights)
   Credits to user Dr_P at http://mjlorton.com forum
   
*/
int fogL = 8;                               // 55W Relay for L fog lamp
int fogR = 7;                               // 55W Relay for R fog lamp
int indL = 4;                               // Circuit between multiswitch and indicator relay
int indR = 2;                               // Circuit between multiswitch and indicator relay

void SignalHigh() {
  digitalWrite(fogR, HIGH);
  digitalWrite(fogL, HIGH);
}

void setup() {
  pinMode(fogL, OUTPUT);
  pinMode(fogR, OUTPUT);
  pinMode(indL, INPUT);
  pinMode(indR, INPUT);
  attachInterrupt(1, SignalHigh, RISING);
}

void loop() {
  int i = 100;                                    // counter initialized with "done" value

  if (digitalRead(indR)) {
    i=0;                                          //if indicators were reversed, the cycle needs to be reset to full 5s
    while(digitalRead(indR) && i<100) {
      i++;
      digitalWrite(fogR, HIGH);
      digitalWrite(fogL, LOW);
      delay(50);
    }
  }
  if (digitalRead(indL)) {                        //same as right side
    i = 0;
    while(digitalRead(indL) && i<100) {
      i++;
      digitalWrite(fogR, LOW);
      digitalWrite(fogL, HIGH);
      delay(50);
    }
  }
  if (!digitalRead(indR) && !digitalRead(indL))   // no indicators currently on
    if (i == 100) {                               //neither indicators were on OR the 5s cycle is over
      digitalWrite(fogR, LOW);
      digitalWrite(fogL, LOW);
    } else                                        //one or both indicators were on for less than 5s
      while(!digitalRead(indR) && !digitalRead(indL) && i<100) { //but not any more
        i++;                                      //finish the 5s cycle in the last foglight configuration
        delay(50);
      }
}

PeterH


After changing RISING to INPUT - both lamps are on permanently..


I can't think of any place where it would be correct to use RISING where it would also be correct to use INPUT.
I only provide help via the forum - please do not contact me for private consultancy.

JimEli


After changing RISING to INPUT - both lamps are on permanently..


INPUT is not a proper mode parameter for attachInterrupt. However, it results in generating an interrupt request on the low level of the pin.

AWOL

Quote
Any idea how to fix it?

Post code and schematic
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Hants

#6
May 16, 2013, 02:02 am Last Edit: May 17, 2013, 02:17 am by Hants Reason: 1
[font=Verdana]SORTED[/font][/size]


Code: [Select]

/* Light turning assistant for cars (cornering lights)
Credits to users Dr_P and jucole at http://mjlorton.com forum

Version designed for use with relays equipped with photocoupler (JD-VCC pin)
(Pinout bank 1: [[JD-VCC, VCC]], GND;                        Pinout bank 2: GND, IN1, IN2, VCC)
More details about reversed connection: http://arduino.cc/forum/index.php?topic=79745.0


*/

int fogL = 8;                               // 55W Relay for L fog lamp
int fogR = 7;                               // 55W Relay for R fog lamp
int indL = 4;                               // Circuit between multiswitch and indicator relay
int indR = 2;                               // Circuit between multiswitch and indicator relay
int swBoth = 3;                           // Separate switch for both fog lights


void setup()  {
  pinMode(fogL, OUTPUT);
  pinMode(fogR, OUTPUT);
  pinMode(indL, INPUT);
  pinMode(indR, INPUT);
  pinMode(swBoth, INPUT);
}

void loop() {

  int i=100; // counter initialized with "done" value

  if(digitalRead(indR)) {
    i=0; //if indicators were reversed, the cycle needs to be reset to full 5s
    while(digitalRead(indR) && i<100) {
      i++;
      if(! digitalRead(swBoth) ) {
        digitalWrite(fogR, LOW);
        digitalWrite(fogL, HIGH);
      }
      else {
        digitalWrite(fogR, LOW);
        digitalWrite(fogL, LOW);
      }
      delay(50);
    }
  }

  if(digitalRead(indL)) { //same as right side
    i=0;
    while(digitalRead(indL) && i<100) {
      i++;
      if(! digitalRead(swBoth) ) {
        digitalWrite(fogR, HIGH);
        digitalWrite(fogL, LOW);
      }
      else {
        digitalWrite(fogR, LOW);
        digitalWrite(fogL, LOW);
      }
      delay(50);
    }
  }

  if(!digitalRead(indR) && !digitalRead(indL)) { // no indicators currently on

    if(! digitalRead(swBoth) ) {

      if(i==100) { //neither indicators were on OR the 5s cycle is over
        if(! digitalRead(swBoth) ) {
          digitalWrite(fogR, HIGH);
          digitalWrite(fogL, HIGH);
        }
        else {
          digitalWrite(fogR, LOW);
          digitalWrite(fogL, LOW);
        }
      }
      else  { //one or both indicators were on for less than 5s
        while(!digitalRead(indR) && !digitalRead(indL) && i<100 && !digitalRead(swBoth)  ) { //but not any more
          i++;                           //finish the 5s cycle in the last foglight configuration
          delay(50);
        }
      }
    }
    else {
      digitalWrite(fogR, LOW);
      digitalWrite(fogL, LOW);
    }
  }
}


AWOL

Quote
Code looks like

Can I recommend you use the auto-format tool in the IDE before posting.
I'm getting travel-sick reading that.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Hants


I'm getting travel-sick reading that.



Please, feel free to delete the whole topic.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up