I am a bit new to the VEXcode iq block programming. What is the block code for starting and stopping a motor with the push button (not the controller)?
Thanks
Wayne
Hi Wayne, welcome to the forum!
There are a couple of good examples within VEXcode IQ to help you. Make sure you are in blocks mode (File → New Blocks Project) and then go to File and choose Open Examples.
Using the coloured buttons at the top, choose the light blue Sensing button to see the relevant examples.
For the Touch LED, take a look at the one called “Start Button”. You can also apply some of the same principles (just without the LED colour) to the Bumper Switch too.
Here is a sample program using a Touch LED and a Motor. There are similar examples in the Example link under the VexIQCode File menu.
Configuration:
Code example using the when TouchLED
hat
Thanks for the replies. Not quite what I am looking for. I only need the code for using either the touch sensor or the push button to simply turn a motor on and off.
Thanks for any help
What have you tried so far?
The logic of the program is:
When started:
Wait until bumper pressed
Spin motor forward
Wait until bumper pressed
Stop motor
Loop to beginning.
Do this forever
So from that you should be able to work out the code.
There is an example above. Do you need more instruction?
You can use this link to check out the VexCode IQ tutorials and examples.
Here is the code I created, still not working. The wait until conflict each other
Nearly! Just move the last wait until and the stop inside the loop too. Right now, these never get run since the forever loop runs forever. The blocks outside the loop do not get used.
I also create this code and it worked but I had to add a touch led.
The touch led and bumper are different so there is not conflict. But, I want it to work with just the touch led OR the bumper.
Ahhh, right.
After each time you change the state of the motor, you need another wait until. This time, wait until NOT bumper pressed.
So:
Wait until bumper pressed
Spin motor forward
Wait until NOT bumper pressed
Wait until bumper pressed
Stop motor
Wait until NOT bumper pressed
Loop
Tge NOT command is in the operators, so put the NOT in, and then the bumper pressed inside that.
post #3 should be good
go take a look at it again
That worked!!
Thanks
I’ll include the pic for others to find on this thread.
Thanks again everyone.
I tried that but the two bumper commands were still in conflict
I don’t like code that references motor moving or not. If the motor is accidentally moving (from impact/etc) then your logic breaks. My preference is to check motor velocity (as in ‘set velocity’). Then just toggle it from 0 to 100 or 100 to 0 as needed w/o regard for sending an actual stop/start command.
I would suggest instead of using wait logic that you replace it all with an If-Else block.
If the bumper is pressed, spin motor… else, stop motor
Put all that inside a forever loop