Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@focalintent
Last active December 16, 2015 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save focalintent/5da1daacfac2a75a84ae to your computer and use it in GitHub Desktop.
Save focalintent/5da1daacfac2a75a84ae to your computer and use it in GitHub Desktop.
// Template class for debugging timing with a logic probe. When this object gets created
// it will raise its pin high. When it gets destroyed, it will drop the pin back low. You
// can (ab)use C++'s object life time to use this to time how long a block of code takes.
// see example below
template <int PIN> TB : public FastPin<PIN> {
public:
TB() { static bool bSet=false; if(!bSet) { setOutput(); bSet=true; } hi(); }
~TB() { lo(); }
};
...
// In the code before - every time the loop function is entered, pin10 will be raised high
// and every time the loop is exited, pin10 will be dropped back low. Meanwhile, the block
// further in will raise pin 11 high just before calling show, and it will drop low again
// afterwards. You can then use a logic probe on pins 10 and 11 to see exactly how long
// each thing takes while going through a loop.
void loop() {
TB<10> loop_pin();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
}
{
TB<11> show_pin();
LEDS.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment