Created
May 13, 2012 18:26
-
-
Save netmute/2689625 to your computer and use it in GitHub Desktop.
Run a loop at defined intervals on Arduino.
This file contains hidden or 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
/* Run a loop at defined intervals. | |
This was tested with an Arduino Uno. | |
Other boards might require tweaking of the boardFrequency constant. | |
*/ | |
/* How many times per second timedLoop() gets executed */ | |
int loopFrequency = 1; | |
void timedLoop() { | |
/* Do stuff. */ | |
} | |
const int boardFrequency = 14796; | |
int freqTimer = 0; | |
void loop() { | |
if ((freqTimer % (boardFrequency / loopFrequency)) == 0) { | |
freqTimer = 0; | |
timedLoop(); | |
} | |
freqTimer++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be safe, you should also do
freqTimer = 0
beforetimedLoop()
, and make it an int.