Go Down

Topic: brake light repeater (Read 1 time) previous topic - next topic


I'm making a clever brake light repeater for my show car

It has an illuminated panel on the back that already lights up dimly '300ZX' when the side lights are on

I want to use 3W LEDs behind each letter so that when you hit the brakes each letter lights up bright in turn until they are all on, stating with the centre '0', then OOZ, then 300ZX - taking a second or so to complete the whole sequence, then they all stay on until you release the brakes.

That's easy enough to figure out how to do.  Thing is I need the 3W LEDs to go off instantly if you take your foot off the brakes, even if it is part way through the sequence, so for example if you just pulse the brakes you just get the centre 0 to flash

How is the best way to go about that?  

I would have thought some sort of interrupt when you release the brakes that turns any illuminated LEDs off and sends the program back to the beginning waiting for the next brake press - but I haven't tried hardware interrupts on Ardunio before.  Is that easy to do?



Sep 23, 2013, 09:17 pm Last Edit: Sep 23, 2013, 09:20 pm by robtillaart Reason: 1
something like this?
Code: (dummy, not tested) [Select]

#define BRAKE_PIN 5

uint32_t lastBlink = 0;
uint32_t interval = 100;

void setup()
 pinMode(13, OUTPUT);

 digitalWrite(13, LOW);

void loop()
 bool blinking = false;
 brakePressed = digitalRead(BRAKE_PIN);

 blinking = (brakePressed == HIGH);
 if (blinking)
   digitalWrite(13, LOW);  // <<< reset sequence

 if (millis() - lastBlink >= interval)
    lastBlink = millis();
    if (blinking) digitalWrite(13, digitalRead13);   // <<<< next step sequence

Only if the blinking == true the next step might be set, of blinking is false the sequence is reset immediately
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


I think this is similar to what robtillart is suggesting, but I'm not sure.

You need to design your sketch so that it does not block. This means that it can continue to poll the input state while it is doing the timing. The blink without delay example sketch demonstrates the principle.

I'd do it like this:

In loop(), read the input state.

If the input state is inactive (brakes off) turn off all the outputs and save the current time as the last time that the brakes were off.
Else the input is active (brakes on) so subtract the last time that the brakes were off from the current time to get how long they have been on for.
If that exceeds a second, turn on the first output.
If it exceeds two seconds, turn on the second output.
If it exceeds three seconds, turn on the third output.
There is plenty of scope to fade these outputs rather than just switching them on if you want to get clever.

Note that none of the logic above involves waiting for anything - loop() would perform this logic each time it is called. Since loop() is called repeatedly, this means the logic would be repeated hundreds of thousands of times a second and just take whatever actions were needed based on changes to the input and the passage of time. There is ample time for your Arduino to deal with other jobs as well, if you wanted.


Thanks guys, that should help a lot

PeterH I found your algorithm very useful as I could not quite figure out what the robtillaart code was doing


Go Up