changeset 4:cb01d3b5b6a7

next_frame function
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Tue, 21 Oct 2014 00:23:16 +0200
parents 88e3f15c500e
children cd880d8c2da3
files nkubik/clock.ino
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/nkubik/clock.ino	Tue Oct 21 00:16:49 2014 +0200
+++ b/nkubik/clock.ino	Tue Oct 21 00:23:16 2014 +0200
@@ -12,3 +12,14 @@
     }
     last = now;
 }
+
+bool next_frame(unsigned int ms) {
+    // Return true if at least ms milliseconds have passed since the last call.
+    static unsigned long last = 0;
+    unsigned long now = millis();
+    if (now >= last + ms || now < last) {
+        last = now;
+        return true;
+    }
+    return false;
+}