4 ms·
That's exactly what's described. Arduino's framework divides main() into two functions: Setup() and loop(), but they're essentially the same as whatever comes
by petsfed 4y ago
That's exactly what's described.
Arduino's framework divides main() into two functions:
Setup() and loop(), but they're essentially the same as whatever comes before the while loop, and the while loop itself, in a standard embedded c main function.
Then you just have interrupts setting states, and the loop responds to the change in state.
- skybrian 4y agoIt's not quite the same as a while loop, because when you return from the loop() function, how long it takes before it gets called again isn't defined. Using arduino-pico, for example, it does some USB I/O handling (when using TinyUSB). If you write an actual while loop and don't return from the loop function often enough, you might starve the USB port implementation. This adds enough of a delay that I moved some code to the other core on the Pico to get precise timing.
- petsfed 4y agoThat's a fair point. I admit, I moved away from the Arduino framework pretty rapidly after embedded development became my job, well before I had to contend with everything else under the hood. I never ran into an issue of quasi-hidden behaviors like that, because I never pushed the thing that hard. It feels a little bit like the Arduino toolset (that is pre IDE 2.0) was designed to discourage people from pushing things that hard.
- skybrian 4y agoWell, it's behavior specific to one board, and perhaps to TinyUSB. But it looks like Arduino has a yield function [1] that you can use to run periodic tasks if you write your own loop. And Teensy calls yield() between calls to loop(). [2] Since switching to VSCode and PlatformIO, I read the source more. (Arduino 1.x discouraged this due to not having easy ways to navigate between callers and callees.) [1] https://www.arduino.cc/reference/en/libraries/scheduler/yield/ https://www.arduino.cc/reference/en/libraries/scheduler/yiel... [2] https://github.com/PaulStoffregen/cores/blob/master/teensy4/main.cpp#L51 https://github.com/PaulStoffregen/cores/blob/master/teensy4/...