Code: Select all
// Import required libraries
#include <iostream>
#include <string>
#include <WiFi.h>
// Replace with your network credentials
static const char* ssid = "ssid";
static const char* password = "password";
void setup()
{
pinMode(2, OUTPUT);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
}
static uint64_t _next_led_blink = 0;
static bool _last_state_of_led = false;
static volatile uint32_t _longest_main_loop = 0;
void loop()
{
uint64_t main_loop_start_us = micros();
if (main_loop_start_us > _next_led_blink)
{
_next_led_blink = main_loop_start_us + 1000000;
digitalWrite(2, !_last_state_of_led);
_last_state_of_led = !_last_state_of_led;
}
uint32_t length_of_main_us = micros() - main_loop_start_us;
if (length_of_main_us > _longest_main_loop)
{
_longest_main_loop = length_of_main_us;
printf("Longest main loop %lu us\n", _longest_main_loop);
}
}