const int buttonPin1 = 2; // Pin voor de aan/uit schakelaar
const int buttonPin2 = 3; // Pin voor de snelheidsaanpassing
const int ledPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; // Pinnen voor de LED's
int ledCount = sizeof(ledPins) / sizeof(ledPins[0]);
int currentLED = 0;
bool increasing = true;
bool animationRunning = false;
int animationSpeeds[] = {100, 200, 300}; // Snelheidsopties in milliseconden
int currentSpeedIndex = 0;
void setup() {
Serial.begin(9600); // Start de seriële communicatie
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
// Lees de knoppen
bool buttonState1 = digitalRead(buttonPin1);
bool buttonState2 = digitalRead(buttonPin2);
// Serial prints toevoegen om de status van de knoppen weer te geven
Serial.print("Button 1: ");
Serial.println(buttonState1);
Serial.print("Button 2: ");
Serial.println(buttonState2);
// Als de eerste knop wordt ingedrukt, wissel de animatie in/uit
if (buttonState1 == HIGH) {
if (!animationRunning) {
animationRunning = true; // Schakel de animatie in als deze is uitgeschakeld
} else {
animationRunning = false; // Schakel de animatie uit als deze is ingeschakeld
// Reset de variabelen voor de volgende keer dat de animatie wordt ingeschakeld
currentLED = 0;
increasing = true;
}
delay(200); // Debounce delay om meerdere keren indrukken te voorkomen
}
// Als de tweede knop wordt ingedrukt, verhoog de snelheid van de animatie
if (buttonState2 == HIGH) {
currentSpeedIndex = (currentSpeedIndex + 1) % 3; // Roteer door de snelheidsopties
delay(200); // Debounce delay
}
// Voer de animatie uit als deze is ingeschakeld
if (animationRunning) {
digitalWrite(ledPins[currentLED], HIGH);
delay(animationSpeeds[currentSpeedIndex]); // Wacht voor de huidige snelheid
digitalWrite(ledPins[currentLED], LOW);
currentLED += (increasing ? 1 : -1);
if (currentLED >= ledCount) {
currentLED = ledCount - 1;
increasing = false;
} else if (currentLED < 0) {
currentLED = 0;
increasing = true;
}
}
}