I need some help with coding two bumper switches.
I’m trying to have them both run like this:
When button1 is pressed, motor moves at 20 speed
When not pressed, motor doesn’t move
When button2 is pressed, motor moves at -20 speed
When not pressed, motor doesn’t move
It seems every single time I’ve tried this, it only seems to run the button1 code, but button2 doesn’t cooperate (it doesn’t do anything when pressed). Help?
You have your tasks inside your tasks. You need to close task “i_finger” before task “t_finger” begins. Currently, the braces close for “i_finger” after the other tasks, move that last brace to before your second task and see if that works.
This should help with the global scope level and main scope level issues.
Well, it fixed the global issues, but now my program won’t compile. The moment I click “Start” in the program debugger, it starts for not even half a second and stops completely.
Put it in your task main after you start the tasks. Your program is ending right after it gets started, as there is nothing that takes time in the task main. This should hold it open forever.
Your code probably won’t work because it is trying to assign a motor to go at two separate speeds. Try something like this:
This is only capable of setting one motor value. If the 1st touch sensor is pressed, it will set to 20, if the second, it will set to -20, in neither are pressed, it will set to zero. Put this in one of your functions, then delete the other. You can put it in the task main in a while loop because only 1 thing needs to run with this.