Pages: [1]   Go Down
Author Topic: Cornering fog lights / turning assistant.  (Read 424 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
altius, citus, fortius!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/* 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);
                        }
      }
}
« Last Edit: May 14, 2013, 09:19:56 am by Hants » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24427
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you want an interrupt for?
Logged

"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.

USA
Offline Offline
Jr. Member
**
Karma: 2
Posts: 86
If you can't fix it with a hammer, it must be an electrical problem.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

like this?
Code:
/* 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);
      }
}
Logged


UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11195
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

USA
Offline Offline
Jr. Member
**
Karma: 2
Posts: 86
If you can't fix it with a hammer, it must be an electrical problem.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24427
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any idea how to fix it?
Post code and schematic
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
altius, citus, fortius!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SORTED


Code:
/* 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);
    }
  }
}

« Last Edit: May 16, 2013, 07:17:01 pm by Hants » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24427
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
altius, citus, fortius!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm getting travel-sick reading that.


Please, feel free to delete the whole topic.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24427
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, certainly not - why?
Logged

"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.

Pages: [1]   Go Up
Jump to: