void loop() { unsigned long currentMillis = millis(); if (patternStartTime == 0) { patternStartTime = currentMillis; } unsigned long patternDuration = 5000; // Pattern duration: 5 seconds unsigned long offDuration = 3000; // LED off duration: 3 seconds // Execute pattern for 5 seconds if (currentMillis - patternStartTime < patternDuration) { executePattern(); } else { // Turn off LEDs for 3 seconds after pattern execution if (offTime == 0) { turnOffAll(); offTime = currentMillis; } if (currentMillis - offTime >= offDuration) { // Reset variables for the next pattern patternIndex = (patternIndex + 1) % 4; // Change to the next pattern patternStartTime = 0; offTime = 0; Serial.print("Pattern: "); Serial.println(patternIndex); } } readSensorData(); // Read sensor data and print }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter