Skip to content

Example for setEvent #184

@W4KRL

Description

@W4KRL

Please provide an example to call a function every 5 seconds. This code causes myFunction to be called thousands of time a second:

#include <WiFi.h>
#include <ezTime.h>

// Replace with your network credentials
const char* ssid     = "your-SSID";
const char* password = "your-PASSWORD";

Timezone myTZ;

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  
  // Wait for WiFi to connect
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");

  // Initialize ezTime and set the time zone
  myTZ.setLocation("America/New_York"); // Replace with your time zone

  // Synchronize time
  waitForSync();

  // Set the initial event to call myFunction after 5 seconds
  myTZ.setEvent(myFunction, 5); // 5 seconds

  Serial.println("Setup complete");
}

void loop() {
  // Process scheduled events
  events();
}

// Function to be called every 5 seconds
void myFunction() {
  Serial.println("Function called every 5 seconds");
  
  // Add your code here
  
  // Schedule the next call to myFunction after another 5 seconds
  myTZ.setEvent(myFunction, 5); // 5 seconds
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions