Need help improving program speed because of an undesired pause, Looking for an
beazleybub
Posts: 102
Currently I am using this code to count how many times a·switch has been repeatedly·activated·in one instance·and add the count to VAR temp then continue with the rest of my program.
Unfortunately this is slowing down the rest of my program by 100 ms and causing a undesired pause in the routine that follows it because my overall program loops back to Main: to monitor the switch for the next cycle.
I am trying to find a workaround to monitoring the switch when it is active and only continue to the rest of my program after the switch goes silent.
Because the switch pulses 0,1,0,1,0,1,0,1,0 (OR) "off,on,off,on,off,on,off,on,off" I used the routine No_Press: to give the program a way to see that the switch was currently active and not continue until it was definitely silent.
But this causes the over all speed of my program to slow because it has to loop back to Main:
Any suggestions? Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How can there be·nothing? Nothing is something!
Unfortunately this is slowing down the rest of my program by 100 ms and causing a undesired pause in the routine that follows it because my overall program loops back to Main: to monitor the switch for the next cycle.
I am trying to find a workaround to monitoring the switch when it is active and only continue to the rest of my program after the switch goes silent.
Because the switch pulses 0,1,0,1,0,1,0,1,0 (OR) "off,on,off,on,off,on,off,on,off" I used the routine No_Press: to give the program a way to see that the switch was currently active and not continue until it was definitely silent.
But this causes the over all speed of my program to slow because it has to loop back to Main:
Any suggestions? Thanks
Main: BUTTON 2, 1, 255, 20, btnWrk, 0, No_Press temp=temp+1 No_Press: FOR check = 1 TO 5 IF ButtonLocation = 1 THEN GOTO Main PAUSE 20 NEXT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How can there be·nothing? Nothing is something!
Comments
There are two main subroutines: CountPB and GetPBCount.
CountPB should be called as often as possible. It checks the state of the button and counts transitions from 0 to 1. It also times null periods, so it can detect gaps between groups of button presses.
GetPBCount checks to see if a sufficiently-long gap has transpired between presses. If so it returns (and resets) the count. If not, it returns zero. GetPBCount can be called at your leisure, whenever you want to check if a group of button presses has occurred.
The constant MAXTIMES will depend on the length of the null period you require between groups and how often CountPB is called.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 8/2/2008 8:58:38 PM GMT
Neat snipplet!
I like the way it works very much!
············
Thank you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How can there be·nothing? Nothing is something!