// https://wokwi.com/projects/448153462893255681
// https://forum.arduino.cc/t/atmega328pb-wake-with-button-interrupt/1414866
const byte ledYellow = 10;
const byte ledRed = 8;
const byte ledGreen = 9;
const byte ledBlue = 11;
void setup() {
Serial.begin(9600);
Serial.println("\nWake up!\n");
}
void loop() {
rotate(); // take one step in the rotate pattern if it is time
// this clogs the serial buffer and reduces the speed
// but shows the free running nature of the loop
// static int counter;
// Serial.print(counter); counter++;
// Serial.println(" loop.");
}
void rotate() {
// sequence of pins
const byte ledPins[] = {
ledYellow, ledRed, ledGreen, ledBlue,
};
// compiler alculates lenth of the sequence
const byte lenth = sizeof ledPins / sizeof *ledPins;
static byte pc;
static unsigned long lastTime;
unsigned long now = millis();
if (now - lastTime < 333) return;
digitalWrite(ledPins[pc], LOW);
pc++; if (pc >= lenth) pc = 0;
digitalWrite(ledPins[pc], HIGH);
lastTime = now;
}