I have tried using millis() but it doesn't work
Code: [Select]unsigned long StartTime = millis();later...unsigned long CurrentTime = millis();unsigned long ElapsedTime = CurrentTime - StartTime;That will give you the elapsed time in milliseconds, up to about 40 days. If you need more precise measurement you can use 'micros()' instead of ''millis()' to get microseconds, up to a couple of hours, I think.The Arduino clock isn't very accurate so your timing may be off by minutes a day.
unsigned long StartTime = millis();later...unsigned long CurrentTime = millis();unsigned long ElapsedTime = CurrentTime - StartTime;
I am using this code, but when I printout the elapsedTime sometimes I get the number which is not "useful" e.g. StartTime: 313239 CurrentTime: 313247 ElapsedTime: 4294967288 Any idea what this is, and how to avoid this, if I want to use the elapsedTime in further code.
FWIW, once you get ready to finalize the code, try to compress all the math calcs in this example into a constant float or long up front. The reason being, there is no benefit to recalculating "2.0*pi* 3600 * 1000" over and over, it's 22619467.11... Ideally, Define R in that function as well and you may not even need to use a float.Less calculations for Arduino to do = better responsiveness by Arduino.