![]() ![]() If you’re new to this, and maybe even if you’re not, you’re probably wondering how that’s even possible. It works exactly as you’d hope! unsigned long lastTime = 0 unsigned long lastRun = 0 īut this one, this one is good. This would be bad if you were doing something like transmitting on a Particle Electron and were using up your data allowance! unsigned long nextRun = 0 Īnd this similar recipe, that doesn’t quite work either. When you get close to the limit, adding 1000 (in the example) wraps around to being a small number, so for a period of time the code in the if statement will get executed on every single loop. It does not, however, handle rollover properly. Here’s a simple recipe that you see pretty often. But ideally, the device should be able to run forever without rebooting, so here are some handy tips for properly dealing with millis(). Some programs even force the device to reboot periodically, say once every few weeks this could be used to clear memory fragmentation and other issues. Now in reality, most devices will reboot before 49 days. Note: The return value for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints. This number will overflow (go back to zero), after approximately 49 days. ![]() Returns the number of milliseconds since the device began running the current program. It executes very quickly and has a good resolution (milliseconds). The millis() function is handy for timing things with the Particle Photon (and Electron, and Core). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |