Trying to have PIN 5 on my ESP32 turn on and off ranging from 1Hz to 25Hz depending on what I select. Is there an easier method of doing this besides calling a function to do like
ESP32 has a feature called "LedC" which would take care of it for you. Unfortunately, it has a minimum frequency of 10Hz. That still covers more than half the frequency range you wanted.
Ah was a bit busy, thank you for your responses, so first
I have the second core already in use for other tasks and so far my solution was to alternate between both cores to run the digitialWrite code but obviously if both cores are busy I cannot continue.
I have LedC written for another pin and I would prefer to use less than 1Hz but I may include it as a backup to run from 10Hz to 25Hz, its more less just switching that PWM frequency because I know it has to be initialized at that frequency first.
The square wave one actually doesn't look too impossible my only concern is if I can run other things in the meantime while its outputting like a 5Hz 3.3V wave?
It sounds as if your problem is more complicated than just flashing an LED. Have you considered using something like a nano to do the simple hardware handling?
You seem to forget that delay on an ESP32 is not implemented as busy waiting, like on an AVR,
so a delay reschedules the thread and yields to other tasks.
OHHHH UUU RIGHHHTTT, then yeah I would see if I could write another task with a higher priority and when the first task has a delay it would do the second task right?
Perhaps you have misunderstood my suggestion.
1: Use the ESP32 to do all your complicated stuff
2: Farm out some (or all) of the hardware handling to a second arduino - which need only be a simple device - a nano, micro, whatever.
Its like if the managing director is too busy to do their job properly, get them a secretary
Ahhh I see what you mean, I was considering this but the space in the enclosure I designed is too little. For now allocating tasks seems better working for the ESP32 as I have no more issues generating a constant square wave.