-
-
Save focalintent/5da1daacfac2a75a84ae to your computer and use it in GitHub Desktop.
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
// 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