IOT 2

PHOTO EMBED

Mon Jan 08 2024 17:20:22 GMT+0000 (Coordinated Universal Time)

Saved by @马丽

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
}
content_copyCOPY