Car Indicator

I am a 14 year old that is trying to make an interface in my dads kit car that takes in 2 momentary switch's and control 2 relay modules for the indicators in a car. I have had a go at coding it and have got them to work to some extent but they don't always respond to the button press or you have to hold the button in. All advice or changes to the code are very welcome.

I have also made the switch's send a LOW input when pressed, and the relay modules respond to a LOW input to switch.

Thanks, Leo

westfeld.ino (1.16 KB)

// These are all outputs
const int LHindicator = 8; 
const int RHindicator = 9;  
const int SideLights = 10;  


//These are all inputs
const int LHindicator_Sw = 2;
const int RHindicator_Sw = 3;
const int SideLights_Sw = 4;
   


void setup() {
  //These are all outputs
  pinMode(LHindicator, OUTPUT);  
  pinMode(RHindicator, OUTPUT);
  pinMode(SideLights, OUTPUT);


  //These are all inputs
  pinMode(LHindicator_Sw, INPUT_PULLUP);
  pinMode(RHindicator_Sw, INPUT_PULLUP);
  pinMode(SideLights_Sw, INPUT_PULLUP);

  
 digitalWrite(LHindicator, HIGH);
 digitalWrite(RHindicator, HIGH);
 digitalWrite(SideLights, HIGH);
}

void loop() 
{
  if (digitalRead(LHindicator_Sw) == LOW){
  delay(75);  
    while(digitalRead(LHindicator_Sw) != LOW){
      digitalWrite(LHindicator, LOW);
      delay(500);
      digitalWrite(LHindicator, HIGH); 
      delay(500);
    }
  delay(75);
  }
  if (digitalRead(RHindicator_Sw) == LOW){
  delay(75);
      while(digitalRead(RHindicator_Sw) != LOW){
      digitalWrite(RHindicator, LOW);
      delay(500);
      digitalWrite(RHindicator, HIGH);
      delay(500);
      }
  delay(75);
  }
  
}

To make it responsive, all those delays have to go.
Take a look in the IDE's examples at the "blink without delay" and "state change" examples.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.