Hi there I was wanting to know how to make it so pressing a button twice makes it stop and pressing it once makes it start in VEX Code V5 Blocks?
How to make it so pressing a button twice makes it stop and pressing it once makes it start in VEX Code V5 Blocks?
Do a search on the term Latch
Thank you so much for your help
Do you want to start and stop the motor with the same button, or do you want to click the button once to start it and double click to stop? If you are going for the first option this was a big help to me: Vex IQ block coding to start and stop a motor with the same button (it does have a V5 option). If you are going for the second option, however, I am the wrong guy to ask. Good luck.
If you are trying to do the second thing that ulyssesbarth said, you may be able to add some variables to keeps track of how many times the button has been pressed in the time that has passed compared to how many times it could be pressed.
Three variables can be made called
timesPassed (how many times the while loop has run),
timesPressed (how many times the button was pressed), and
possibleTimesPressed (the window of time you want to have to double press)
Every time the while loop runs, add 1 to
timesPassed and if the button was pressed, add 1 to
possibleTimesPressed check how many times the button was pressed in
timesPressed. You now have a count of how many times that button was pressed in the interval you set. After all this, reset
timesPassed to 0 and start it all over again so you can continue to double press to your heart’s content. Also, if the interval to double click is too fast, you can increase
possibleTimesPressed to give you more time to double press.
There is most likely a better way to do this but this is what popped into my head. If you have questions, please feel free to ask!