Arduino Esp32 use millis() to put commands in sequence. Without delay

unsigned long then = 0;
unsigned long intervals[4] = { 0, 2000, 4000, 6000 };
int current_interval_index = 0;
void setup() {
    Serial.begin(115200);
}


void loop() {
    unsigned long now = millis();
    if (now - then >= intervals[current_interval_index]) {
        switch (current_interval_index) {
        case 0:
            Serial.println("Function 1");
            break;
        case 1:
            Serial.println("Function 2");
            break;
        case 2:
            Serial.println("Function 3");
            break;
        case 3:
            Serial.println("Function 4");
            break;
        }
        then = now;
        current_interval_index = (current_interval_index + 1) % 4; // increment index and wrap it back to zero, if it goes to 4 
    }
}
use millis to sequence
the miricle board

A high percentage of this code probably came from someone else. I do not know how to write code, but I can sometimes paste things together that work. Even if the code shown here did not come from one of the sources below, I most likely learned how to make it work with help from them. My apologies to anyone I missed. Please make use of anything you see here, but do not count on good coding practice as I have just done what was needed to make it work. But it does work, unless otherwise noted. Thanks to everyone who has shared their knowledge and good luck to those who are learning. https://www.jarutex.com/index.php/2021/12/19/8868/ https://www.arduino.cc/ https://www.sparkfun.com/ https://randomnerdtutorials.com/ https://youtu.be/3BWSSpcn95A https://stackoverflow.com/ https://youtu.be/684KSAvYbw4 https://exploreembedded.com/ https://www.youtube.com/watch?v=JmvMvIphMnY&t https://prosperityconsulting.com

Loading

Please share it. Thanks!