by Fritzoid » Mon Sep 19, 2011 12:06 pm
by Fritzoid
Mon Sep 19, 2011 12:06 pm
You can use the fact that the callback routine is run at regular intervals to approximate what you want. Since the callback routine runs once every 0.007825 seconds the processor would take 512 passes through the routine over a 4 second span. You can read the port value in the callback routine and increment a counter if the value is high. If the value is low you clear the counter. If the counter reaches 512 then you can be pretty sure that the port has been high for the last 4 seconds.
You can use the fact that the callback routine is run at regular intervals to approximate what you want. Since the callback routine runs once every 0.007825 seconds the processor would take 512 passes through the routine over a 4 second span. You can read the port value in the callback routine and increment a counter if the value is high. If the value is low you clear the counter. If the counter reaches 512 then you can be pretty sure that the port has been high for the last 4 seconds.