Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for setEvent #184

Open
W4KRL opened this issue Dec 21, 2024 · 1 comment
Open

Example for setEvent #184

W4KRL opened this issue Dec 21, 2024 · 1 comment

Comments

@W4KRL
Copy link

W4KRL commented Dec 21, 2024

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
}
@W4KRL
Copy link
Author

W4KRL commented Dec 21, 2024

OK ://)

myTZ.setEvent(myFunction, myTZ.now() + 5);

works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant