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]
/*
// 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