unsigned long previousMillis = 0; // Stores the last time the LED state was updated
const unsigned long interval = 125; // Interval at which to change the sequence step (milliseconds)
int ledPins[] = {3,5,4,2};
int ccwledPins[]={12,10,9,11}; // Array of LED pins
int currentStep = 0;
int cwcurrentStep = 0;
int cwStep = 0;
int ccwStep = 0; // Tracks the current step in the sequence
const int numLeds = 4;
const int ccwnumLeds = 4; // Total number of LEDs
void setup() {
// Set all LED pins as outputs
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
for(int a = 9; a < ccwnumLeds; a++){
pinMode(ccwledPins[a], OUTPUT);
}
}
void bubbleCw() { //Clockwise Rotation
unsigned long currentMillis = millis(); // Get the current time
// Check if the required interval has passed
if (currentMillis - previousMillis >= interval) {
// Save the current time for the next comparison
previousMillis = currentMillis;
// Turn off the previous LED
digitalWrite(ledPins[currentStep], LOW);
digitalWrite(ccwledPins[currentStep],LOW);
// Move to the next step in the sequence
currentStep++;
// If we've reached the end of the sequence, loop back to the first LED
if (currentStep >= numLeds) {
currentStep = 0;
}
// Turn on the current LED
digitalWrite(ledPins[currentStep], HIGH);
digitalWrite(ccwledPins[currentStep],HIGH);
}
}
void loop(){
bubbleCw();
}