Go Down

Topic: Third brake light  (Read 670 times) previous topic - next topic

artois

Hi all,
 I'm trying to implement a led to stay constant on, after a set time, after its blinking state.I have tried most avenues i could think of and getting nowhere. Any help please ?
Code: [Select]
[code]
/*
  //  Automotive Third Brake Light Switch.
  //  Turns on and off a light (LED) connected to a digital pin.
  //  After a set time, light stays constant on.
*/

// constants won't change. Used here to set a pin number :
const int ledPin =  13;        // the number of the LED pin
int pinButton = 2;             //the pin where we connect the button
// Variables will change :
int ledState = LOW;            // ledState used to set the LED
unsigned long previousMillis = 0;        // will store last time LED was updated
// constants won't change :
const long interval = 80;          // interval at which to blink (milliseconds)

void setup() {

  pinMode(pinButton, INPUT); //set the button pin as INPUT
  pinMode(ledPin, OUTPUT);   // set the digital pin as output:
}

void loop() {

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {

    // save the last time you blinked the LED
    previousMillis = currentMillis;
    digitalWrite(ledPin, ledState);

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
      //read the state of the button
      int stateButton = digitalRead(pinButton);
      if (stateButton == 1) {     //if is pressed
        digitalWrite(13, HIGH);
      }    // turn the LED on (HIGH is the voltage level)

      if (stateButton == 0)
        digitalWrite(13, LOW);

    }
  }
}


[/code]

Txs John

ieee488


artois

Hi all,
This all works fine to here, Sorry I forgot to show the code to switch from the led blink state to stay on state for set period. I deleted it cause I tried all but no success, any hint to what to do please.

john

rickso234

Seems like overkill to use an Arduino, but a good learning project. This can all be accomplished with a 555 Timer and a few RC networks. I once built the circuit inside a cylindrical array of LEDs, in the form factor of the original brake light bulb. Darned if I remember where the schematic is though.

Go Up