This gist was automatically pasted at the request of the code author or one of the discord server helpers. If you have any suggestions or bugs to report, you can do so on our GitHub repository, or in our discord server. This project is run by volunteers so feel free to fork and commit your changes then open a pull request!
Created
January 7, 2021 08:59
-
-
Save ArduinoDiscordBot/45811ace80af4d34b2c76fd63a4f3829 to your computer and use it in GitHub Desktop.
Code by Weepwoop#4800 - Thu Jan 07 2021 08:59:47 GMT+0000 (Coordinated Universal Time)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c++ | |
#include <iostream> | |
#include <limits> | |
/* | |
This is supposed to be a small replication of | |
what happens when my old code is opposed with | |
millis() rollover. | |
*/ | |
int main() | |
{ | |
const unsigned long ulong_max = std::numeric_limits<unsigned long>::max(); | |
std::cout << "Unsigned Long :: Max = " << ulong_max << std::endl; | |
// PreviousTime was 120 ms ago from the 0 of unsigned long | |
// I'm interpreting it like a clock. so 0, would | |
// be the 12 in real world clock. | |
unsigned long previousTime = ulong_max - 120; | |
// timeNow is 12 ms o'time (because of rollover) | |
unsigned long timeNow = 12; | |
// deltaTime is the difference between timeNow and previousTime | |
unsigned long deltaTime = timeNow - previousTime; | |
/* | |
Expected Logically: | |
- DeltaTime should be: | |
PreviousTime was 120 + 12 ago. | |
PreviousTime = 132 | |
Code Output: | |
- Output = 133 | |
*/ | |
std::cout << "deltaTime: " << deltaTime << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment