Posted in another forum and noticed errors. Tried to correct, but lost the main body. So…
I'm working on a project to replace the stock (incandescent) bulbs in my car's indicators with LED "bulbs". I've figured out the hardware (i.e. changing between the car's ˜12V and Arduino 5V) as well as building the LED "bulbs".
I'm now working on the code and have hit a couple of roadblocks. What I need to do is read 4 inputs and output to LED arrays depending on the input combinations. The outputs will differ depending on the inputs (i.e. output for Brake input will be different than output for Brake and Left-turn combined).
I've figured out how to code the outputs based upon different input combinations, but what I don't know is how repeat the output until ANY one of the 4 inputs changes, then stop the output sequence and return to the top of the loop. So, I need the code to do this:
- Read 4 inputs
- Output to 8 pins depending on inputs and repeat until
- Detect change on ANY input
- Stop and return to the top
For the 4 inputs, there are 7 possible input combinations (brake, left-turn, right-turn, brake & left-turn, etc.) and 8 different output combinations. I should also mention that the turn indicators are 3-bulb sequentials (as are original standard on my '68 T-Bird) which explains the delay functions is some of the code.
Here's what I have so far:
int outPin = 0;
int inPin = 0;
int setPin = 0;
int pinRead = 0;
int lightPin = 0;
void setup()
{
for (int outPin = 0; outPin < 8; outPin++); { //set pins 0 thru 7 as OUTPUT
pinMode(outPin, OUTPUT);
}
for (int inPin = 9; inPin < 13; inPin++); { //set pins 9 thru 12 as INPUT
pinMode(inPin, INPUT);
}
for (int setPin = 0; setPin < 8; setPin++); { //set all pins to LOW
setPin = LOW;
}
}
void loop()
{
for (int pinRead = 9; pinRead < 13; pinRead++) { //read pins 9 thru 13
digitalRead (pinRead);
}
// write to OUTPUT pins based on INPUT pin combinations (7 different combinations)
if (9 == HIGH && 10 == LOW && 11 == LOW && 12 == LOW) { //Brake
for (int lightPin = 0; lightPin < 8; lightPin++)
digitalWrite(lightPin, HIGH);
} else if (9 == LOW && 10 == HIGH && 11 == LOW && 12 == LOW) { //LeftTurn
digitalWrite (0, HIGH);
delay(500);
digitalWrite (1, HIGH);
delay(500);
digitalWrite (2, HIGH);
delay(500);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
delay(1000);
} else if (9 == LOW && 10 == LOW && 11 == HIGH && 12 == LOW) { //RightTurn
digitalWrite (3, HIGH);
delay(500);
digitalWrite (4, HIGH);
delay(500);
digitalWrite (5, HIGH);
delay(500);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
delay(1000);
} else if (9 == LOW && 10 == LOW && 11 == LOW && 12 == HIGH) { //Hazard
digitalWrite (0, HIGH);
digitalWrite (3, HIGH);
delay(500);
digitalWrite (1, HIGH);
digitalWrite (4, HIGH);
delay(500);
digitalWrite (2, HIGH);
digitalWrite (5, HIGH);
for (int lightPin = 0; lightPin < 6; lightPin++)
digitalWrite(lightPin, LOW);
delay(1000);
} else if (9 == HIGH && 10 == HIGH && 11 == LOW && 12 == LOW) { //LeftBrake
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (5, HIGH);
digitalWrite (0, HIGH);
delay(500);
digitalWrite (1, HIGH);
delay(500);
digitalWrite (2, HIGH);
delay(1000);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
} else if (9 == HIGH && 10 == LOW && 11 == HIGH && 12 == LOW) { //RightBrake
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
delay(500);
digitalWrite (4, HIGH);
delay(500);
digitalWrite (5, HIGH);
delay(1000);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (5, LOW):
} else if (9 == LOW && 10 == LOW && 11 == LOW && 12 == LOW) { //ALL OFF
for (int lightPin = 0; lightPin < 8; lightPin++);
digitalWrite (lightPin, LOW);
}
}
So, what I need to know is:
- How do I repeat the resulting functions of an individual "if" statement
- How to detect a change in ANY of the 4 inputs during that repeat, and
- Stop the "repeat" and return to the top of the loop upon #2