Arduino > Arduino

Cornering lights/turning assistant and fog lights-again (but different problem)

(1/3) > >>

Hants:
I am struggling with adding another functionality - both lamps ON. Has anybody got an idea how to add this feature without destroying code that has been written by Dr_P?


--- 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);
                        }
      }
}
--- End code ---

Mr Eastwood:
Hi,  is this what you mean ?



--- Code: ---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 = ?????;


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

--- End code ---

Hants:
Sadly.. Nope.

Now both lamps are going ON for 5 seconds when I switch 'indL' or 'indR.'

'swBoth' doesn't do anything

 :'(


Thanks for trying!

dr_p:
In addition to what you had initially, you want a push-button to light both fog lights? And I suppoze it has priority over everything else?

Mr Eastwood:

--- Quote from: Hants on May 15, 2013, 07:43:58 AM ---Sadly.. Nope.
Now both lamps are going ON for 5 seconds when I switch 'indL' or 'indR.'
'swBoth' doesn't do anything

--- End quote ---

doh! sorry i missed the digital read!   hopefully now when swBoth input is switched "high" both fog lights will come on when you use the LH RH indicator; and when "low" it will work as normal;  if not, I'm going to throw all my microchip pics into the bin!! ;-)

replace ...

--- Code: ---if(!swBoth) {

--- End code ---

with..

--- Code: ---if( !digitalRead(swBoth) ) {

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version