Hi, I'm new to Arduino. I am trying to program a 3 LED sequencer like the old Cougar tail lights. I have a sketch that does what I want, but using the delay doesn't let the bulbs extinguish right away every time. I tried to format the blink without delay for what I need, but it just randomly flashes instead of sequencing. Can someone help me implement the mills() timer and remove the delay. The LED's are supposed to light up in sequence, staying lit until the final one lights, and then they all shut off. Or, if the input is still HIGH, they will stay lit. Thanks
C:
const int brakesPin = 2; // the number of the pushbutton pin
int timer = 200; // The higher the number, the slower the timing.
// variables will change:
int brakesState = 0; // variable for reading the pushbutton status
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 10; thisPin < 13; thisPin++) {
pinMode(thisPin, OUTPUT);
pinMode(brakesPin,INPUT);
}
}
void loop() {
// read the state of the pushbutton value:
brakesState = digitalRead(brakesPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (brakesState == HIGH)
// loop from the lowest pin to the highest:
for (int thisPin = 10; thisPin < 13; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
}
else // turn the pin off:
for (int thisPin = 10; thisPin < 13; thisPin++)
{
digitalWrite(thisPin, LOW);
}
}
Last edited: