Hey all, im looking into doing set heights, and would like to know how to make a function where every press of a single button increases the variable value by one, and another button that decreases by one that can count multiples. like press the button 7 times the variable equals 7. Thanks
The trick of these button press functions is to not increment too quickly as you loop through. Otherwise you will cycle through a lot more than you want in a real short amount of time.
Upon detecting button press, you can set a minimum time until next event to process or look for a button no longer being pressed to start looking again.
Otherwise you will probably loop through the entire set of values right away as the user control loop will hit that code many times within one second. So put some way of waiting for some state change (enough time or the button up event to be detected) before you let the next value come along.
The other thing to consider is having background tasks running the code performing the action versus detecting the change in the user control and running a function to do the activity. That would cause the rest of the user control loop to sit there and wait for your function to finish.
This thread has some good hints on how to do this… post #9 but it’s written for Convex vexControllerGet(Btn8U) is kind of like vexRT[Btn8u]
Typing with my nook don’t hate:
int count = 1;
The program we love to use as a background loop. We use this as autonomous selection interface, viewing multiple sensor values and variables during autonomous, so many things. But for three lift preset heights, I suggest programming three buttons. For the skyrise, unless you have a very reliable lift with potentiometer, it can be difficult to program 7 precise and reliable heights. With encoders, if you forget to zero things out correctly, you are out, so be careful.
Our double reverse six bar has insane amount of mixed rubber band assist and a poorly tuned PD controller, so things get springy a lot like a pneumatic lift. We tried to optimize preset values, but although the lift is strong and fast, heights change a lot due to voltage/rubber bands/sensor getting loose:p And, remember to have protection in case some outer force stalls your lift in an open or closed loop!!!