-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Description
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
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels