int myPins[]= {6,7,8,9,10,11,12,13};
int pinCount=8;
const long period = 200;
unsigned long start_time = 0;
int trenutnaLED = 0;
int smer = 1;
const int buttonpin = 2;
bool dol = false;
bool lastButtonState = HIGH;
const int DebounceTime = 50;
unsigned long lastDebounce = 0;
void setup() {
pinMode(buttonpin, INPUT_PULLUP);
for (int thisPin=0; thisPin <pinCount; thisPin++){
pinMode(myPins[thisPin],OUTPUT);
}
}
void loop() {
unsigned long current_time = millis();
bool button_state =digitalRead(buttonpin);
if (button_state != lastButtonState) {
lastDebounce = current_time;
}
if ((current_time - lastDebounce) > DebounceTime) {
if (button_state == LOW && !dol) {
dol = true;
smer = -smer;
}
else if (button_state == HIGH && dol) {
dol = false;
}
}
lastButtonState = button_state;
if (current_time - start_time >= period){
start_time = current_time;
for (int thisPin=0; thisPin <pinCount; thisPin++){
digitalWrite(myPins[thisPin], LOW);
}
digitalWrite(myPins[trenutnaLED], HIGH);
trenutnaLED += smer;
if (trenutnaLED >= 8) {
trenutnaLED = 8 - 1;
smer = -smer;
}
else if (trenutnaLED < 0) {
trenutnaLED = 0;
smer = -smer;
}
}
}