int led_array[] ={ 10, 11, 12 };
int led_count = 3;
volatile int led_pos = 0;
int button_pin = 2;
unsigned long previousMillis = 0;
const long period = 500;
int ledState = HIGH;
void change() {
led_pos = (led_pos +1) % 4;
}
void setup() {
for (int this_led =0; this_led < led_count; this_led++){
// hier pak ik het value van de array en set de pinmode out
pinMode(led_array[this_led], OUTPUT);
//set vlue pin te low zodat die uit is
digitalWrite(led_array[this_led], LOW);
}
pinMode(button_pin, INPUT);
//attachInterrupt(digitalPinToInterrupt(2), RISING, CHANGE);
attachInterrupt(0, change, RISING);
}
void loop() {
for (int this_led = 0; this_led < led_count; this_led++){
if( this_led == led_pos ){
digitalWrite(led_array[this_led], HIGH);
} else {
digitalWrite(led_array[this_led], LOW);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= period) {
previousMillis = currentMillis;
if (led_array[this_led] == HIGH) {
(led_array[this_led])= LOW;
} else {
ledState = HIGH;
}
}
}
}
}
Eigen_Project.ino (1.79 KB)