Hey All,
I'm trying to make a Sequential Turn Signal for my 1955 Buick, I'm looking to put these onto the front fenders where the car has ports which are only there for looks.
here's what I got so far.
when I send it, it works for a second and nothing.
I can get it to work of I only program one Turn Signal, but I need both....
int left = 12; //Left Turn Signal
int left1 = 2; //LED 1 for left signal indicator
int left2 = 3; //LED 2 for left signal indicator
int left3 = 4; //LED 3 for left signal indicator
int right = 13; //Right Turn Signal
int right1 = 5; //LED 1 for right signal indicator
int right2 = 6; //LED 2 for right signal indicator
int right3 = 7; //LED 3 for right signal indicator
int buttonState = 0;
void setup() {
pinMode(left1, OUTPUT);
pinMode(left2, OUTPUT);
pinMode(left3, OUTPUT);
pinMode(right1, OUTPUT);
pinMode(right2, OUTPUT);
pinMode(right3, OUTPUT);
pinMode(left, INPUT);
pinMode(right, INPUT);
}
void loop() {
buttonState = digitalRead(left);
if (buttonState == HIGH) {
digitalWrite(left1, HIGH);
delay(225);
digitalWrite(left1, LOW);
delay(225);
digitalWrite(left2, HIGH);
delay(225);
digitalWrite(left2, LOW);
delay(225);
digitalWrite(left3, HIGH);
delay(225);
digitalWrite(left3, LOW);
delay(225);
}
else {
}
buttonState = digitalRead(right);
if (buttonState == HIGH) {
digitalWrite(right1, HIGH);
delay(225);
digitalWrite(right1, LOW);
delay(225);
digitalWrite(right2, HIGH);
delay(225);
digitalWrite(right2, LOW);
delay(225);
digitalWrite(right3, HIGH);
delay(225);
digitalWrite(right3, LOW);
delay(225);
}
else {
}
}
I don't see anything wrong... I haven't tried it out, so I can't say for sure.
Is the right side failing? It might be your hardware... I'm wondering it the LED connected to pin 13 on the board might be interfering with your circuit (if you are using a pull-up resistor or something). Maybe you can switch the pins around and use pin 13 as an output pin?
This shouldn't mess-up your code, but you don't need the else statements. They are optional with if, and they are not doing anything.
The code looks as if it should flash the lamps correctly, although I think you might find the lack of responsiveness to switch inputs irritating and you will probably want to fix that. But it should basically work. You haven't got any serial port output there so we can't tell whether the Arduino is running or what it thinks it's doing. How is it being powered? What are you using for the switch inputs and how are they connected? What are you using for the turn signals, and how are they powered and connected?
How about sending some debugging stuff to the Serial Monitor so that you can see what's happening? Until you know where your program fails, you won't be able to solve the problem.
You don't need to fix it to get the solution working, but the fix would be to change the overall structure of the code. Instead of using blocking code which waits for each flash sequence to complete before it re-reads the switch input, you would use a non-blocking approach to poll the switch and turn the lamps on and off as required. The 'blink without delay' is a simple example of a non-blocking sketch.
dasaint80:
I was under the undestanding that serial port was only for LCDs, can I get a link for the serial port usage?
The hardware serial port can be used to connect to a wide variety of devices, but it's particularly useful as a debugging aid. You initialise the serial port by a call to Serial.begin(9600); you do this once, within setup().
In the remainder of the code, add calls to Serial.println("Your message here") to send a text message to the serial port. Insert these print statements at points in your code which tell you what the sketch is doing and why. You can print variables as well as fixed strings - look at the documentation for Serial.print and Serial.println.
After you have uploaded your sketch, open the serial monitor window in the IDE. All the output your sketch writes to the serial port will be displayed in the serial monitor window. Note that most Arduinos will reset each time you open the serial monitor window.
dasaint80:
The turn signal switches on the steering column. it's a three way switch on-off-on
How are these connected to the Arduino inputs i.e. what is the circuit?
dasaint80:
LEDs I was gonna power them with individual relays to Left and Right.
I meant what are you using now? Are you using LEDs? Are these powered directly from the Arduino output pins? What current do they draw, and have you used current-limiting resistors to control that current?
instead of stepping down your car power to 9v and letting the board step it down to 5 v, which I assuem is what you plan on doing, you could get a 12v-5v regulator and wire it directly to the 5 v rail on your arduino, will make the board run a tiny bit cooler since the voltage regulator wont be doing anythin.g
I got this code from the forum, i modified it and working very well but in that case the leds flows from A to B to light up evey led and then from A to B to shut every led. What i want is to cut that seccond thing. I want to shut all diodes instantly and then loop again from A to B.
So...
Press the turn leds starts from A to B staying light up for about 500ms and all shut off, and then again from A to B.
long sequenceDelay = 20; //time it takes between led's
long sequenceDelay2 = 40;
long sequenceDelay3 = 60;
long sequenceDelay4 = 80;
long sequenceDelay5 = 100;
long sequenceDelay6 = 120;
long flashDelay = 1046;
long flashDelay2 = 1000; //time LED is on
long flashDelay3 = 1000;
long flashDelay4 = 1000;
long flashDelay5 = 1000; //time LED is on
long flashDelay6 = 1000;
boolean LED10state = false; // the LED will turn ON in the first iteration of loop()
boolean LED11state = false; // need to seed the light to be OFF
boolean LED12state = false;
boolean LED13state = false; // the LED will turn ON in the first iteration of loop()
boolean LED14state = false; // need to seed the light to be OFF
boolean LED15state = false;
boolean LED5state = false; // the LED will turn ON in the first iteration of loop()
boolean LED6state = false; // need to seed the light to be OFF
boolean LED7state = false;
boolean LED4state = false; // the LED will turn ON in the first iteration of loop()
boolean LED3state = false; // need to seed the light to be OFF
boolean LED2state = false;
long waitUntil10 = 0;
long waitUntil11 = sequenceDelay; // the seed will determine time between LEDs
long waitUntil12 = sequenceDelay2;
long waitUntil13 = sequenceDelay3; // the seed will determine time between LEDs
long waitUntil14 = sequenceDelay4;
long waitUntil15 = sequenceDelay5;
void setup() {
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(15, OUTPUT);
pinMode(14, OUTPUT);
pinMode(13, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(10, LED10state); // each iteration of loop() will set the IO pins,
digitalWrite(11, LED11state);
digitalWrite(12, LED12state);
digitalWrite(5, LED5state); // each iteration of loop() will set the IO pins,
digitalWrite(6, LED6state);
digitalWrite(7, LED7state);
digitalWrite(13, LED13state); // each iteration of loop() will set the IO pins,
digitalWrite(14, LED14state);
digitalWrite(15, LED15state);
digitalWrite(4, LED4state); // each iteration of loop() will set the IO pins,
digitalWrite(3, LED3state);
digitalWrite(2, LED2state);
// checking to see if enough time has elapsed
if (millis() >= waitUntil10) {
LED10state = !(LED10state);
waitUntil10 += flashDelay;
LED7state = !(LED7state);
waitUntil10 += flashDelay;
// this if-statement will not execute for another 1000 milliseconds
}
// checking to see if enough time has elapsed
if (millis() >= waitUntil11) {
LED11state = !(LED11state);
waitUntil11 += flashDelay2;
LED6state = !(LED6state);
waitUntil11 += flashDelay2;
// this if-statement will not execute for another 1000 milliseconds
}
// keep in mind, waitUntil12 was already seeded with a value of 500
if (millis() >= waitUntil12) {
LED12state = !(LED12state);
waitUntil12 += flashDelay3;
LED5state = !(LED5state);
waitUntil12 += flashDelay3;
}
if (millis() >= waitUntil13) {
LED13state = !(LED13state);
waitUntil13 += flashDelay4;
LED4state = !(LED4state);
waitUntil13 += flashDelay4;
// this if-statement will not execute for another 1000 milliseconds
}
// checking to see if enough time has elapsed
if (millis() >= waitUntil14) {
LED14state = !(LED14state);
waitUntil14 += flashDelay5;
LED3state = !(LED3state);
waitUntil14 += flashDelay5;
// this if-statement will not execute for another 1000 milliseconds
}
// keep in mind, waitUntil12 was already seeded with a value of 500
if (millis() >= waitUntil15) {
LED15state = !(LED15state);
waitUntil15 += flashDelay6;
LED2state = !(LED2state);
waitUntil15 += flashDelay6;
}
}