-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store the millis() value in a unsigned long. #1
Comments
Het unsigned long verhaal begrijp ik. Maar onderstaande niet echt
Op https://github.com/BasOnTech/Arduino-Projects-NL/blob/master/mini-weerstation/mini-weerstation-deel-3.ino#L362 sla ik de huidige millis op. Welke previousMillis wil dan hier vanaf halen? |
I prefer to write in English, so everyone knows what we are talking about. Is that okay ? Your 'currentMillis' was already unsigned long, and of course millis() itself returns an unsigned long. With 'previousMillis' I just ment any variable that remembers a previously value of millis(). The substraction should be with unsigned long. That is all. Examples of the substraction with unsigned long variables:
Or this:
You have fixed that. Thanks. In the file "mini-weerstation-deel-3.ino", there is variable 'buttonLongPressTime' which is used for two things. One thing is to store the millis() value, but the variable is only an 'int'. The other thing is a boolean state. You make it zero when not used. Using a single variable for two completely different things that conflict with each other is not okay. |
Dank, ik ga ernaar kijken :) Ik geef overigens de voorkeur aan Nederlands omdat dit de Nederlandstalige code repo is. Het idee van Bas on Tech is om juist Nederlandse informatie te bieden vandaar dat ik ook de comments in de code in het Nederlands zet. De variabelen en functienamen zijn expres Engels omdat in programmeren Engels veelal de voertaal is. |
The millis() does a rollover from 0xFFFFFFFF to 0x00000000 after about 50 days. To avoid problems, store a millis value always as unsigned long and subtract it with "currentMillis - previousMillis". That substraction with both being unsigned long will result in a valid number, even if millis() is in the middle of a rollover.
The text was updated successfully, but these errors were encountered: