I am having a issue with a program involving leds and a button. The objective is to make the 8 leds turn on and off in sequence with a second in between. And then when i press the button the sequence have to change direction. But that need to happen immediately. In this case i cant use the delay () function.
I wrote the code the best i could but its not working. Can you guys help me out a bit since i am a noob at this.
int val =0;
int buttonPin = 13;
int valor;
long previusMillis = 0;
int ledState;
long interval = 1000;
long currentMillis = millis();
void setup() {
for (int valor = 2; valor < 9; valor++) {
pinMode(valor, OUTPUT);
}
pinMode(buttonPin, INPUT);
}
void loop() {
if (currentMillis - previusMillis > interval){
previusMillis = currentMillis;
if(ledState == LOW){
ledState == HIGH;
}
else{
ledState == LOW;
}
val = digitalRead(buttonPin);
if (val == HIGH) {
if (valor <=2){
valor =10;
}else{
valor--;
}
}
else if (val == LOW) {
if (valor >=10){
valor =2;
}else{
valor++;
}
}
digitalWrite(valor,ledState);
}
}