Discuss Scratch
- Discussion Forums
- » Connecting to the Physical World
- » How to move an ev3 motor while the keyboard arrow is pressed
- cadteacher
-
New Scratcher
25 posts
How to move an ev3 motor while the keyboard arrow is pressed
How to move an ev3 motor while the keyboard arrow is pressed and have the motor stop when it is not pressed? any suggestions
- D-ScratchNinja
-
Scratcher
1000+ posts
How to move an ev3 motor while the keyboard arrow is pressed
when green flag clickedI've never used the EV3, but this would be my script to trigger movement.
forever
if <key [arrow key v] pressed?> then
turn motor [on v] :: pen
else
turn motor [off v] :: pen
end
end
- cadteacher
-
New Scratcher
25 posts
How to move an ev3 motor while the keyboard arrow is pressed
If forgot to mention we are using scratch 3, I think this would work in scratch 2 but we do not have the on/off option in scratch 3
- D-ScratchNinja
-
Scratcher
1000+ posts
How to move an ev3 motor while the keyboard arrow is pressed
Oh, well then you may have to refer to:
when green flag clicked
forever
if <key [arrow key v] pressed?> then
motor [A v] set power to (100) :: pen
else
motor [A v] set power to (0) :: pen
end
end
- cadteacher
-
New Scratcher
25 posts
How to move an ev3 motor while the keyboard arrow is pressed
For some reason the “set motor power” does not seam to work, the motor does not start. Not sure if it intended to work that way or if is intended to set the power of a motor and then use the “motor a turn this way for 1 sec” option and run it at the set power level. Any Suggestion, thoughts…
- D-ScratchNinja
-
Scratcher
1000+ posts
How to move an ev3 motor while the keyboard arrow is pressed
Ok, let's try one more time:
when green flag clicked
motor [A v] set power (slider value)% :: pen
forever
wait until <key [arrow key v] pressed?>
motor [A v] turn [this way v] for (0.06) seconds :: pen
end
- cadteacher
-
New Scratcher
25 posts
How to move an ev3 motor while the keyboard arrow is pressed
I have tried this type of code, but the problem is that it will run for.06 sec and then stop for a fraction of a sec and then start up again. It is not continuous. Are you writing this code with an extension in scratch 2? If you try scratch 3 ev3 extension which is already in scratch 3, id seems to be missing some functionality. If possible try it and let me know what you think.
- D-ScratchNinja
-
Scratcher
1000+ posts
How to move an ev3 motor while the keyboard arrow is pressed
One thing that could help: Turbo Mode (shift-click the green flag)
Or, we probably could try combining:
Or, we probably could try combining:
when green flag clicked
forever
motor [A v] turn [this way v] for (0.06) seconds :: pen
end
when green flag clicked
forever
motor [A v] set power to (0) % :: pen
wait until <key [arrow key v] pressed?>
motor [A v] set power to (100) % :: pen
wait until <not <key [arrow key v] pressed?>>
end
- cadteacher
-
New Scratcher
25 posts
How to move an ev3 motor while the keyboard arrow is pressed
No luck, that didn't work. I never knew about turbo mode. I am pretty sure that the Set motor power on scratch 3 is only to set the motors power, it does not start the motor. I need to use the “turn the motor this wait for 1 sec” for the motor to actually start rotating. Do you have access to scratch 3 & EV3. if you do try it let me know what you think. Thanks
- D-ScratchNinja
-
Scratcher
1000+ posts
How to move an ev3 motor while the keyboard arrow is pressed
Sorry, I've never used the EV3 before, so I don't really have experience. Maybe there are tutorials out there for that sort of stuff?
Oh, and the part where I showed the
Anyway, hope I brought you a step further.
Oh, and the part where I showed the
motor [A v] turn [this way v] for (0.06) seconds :: penactually probably should've been
motor [A v] turn [this way v] for (9999999) seconds :: pen
Anyway, hope I brought you a step further.
- cadteacher
-
New Scratcher
25 posts
How to move an ev3 motor while the keyboard arrow is pressed
I was not able to find any tutorial related to the EV3, but thanks for your help. I will keep looking.
- adazem009
-
Scratcher
100+ posts
How to move an ev3 motor while the keyboard arrow is pressed
Try this:
when green flag clicked
motor [A v] set power to (100)%:: #308e30 stack
forever
if <key [up arrow v] pressed?> then
motor [A v] turn [this way v] for (0.1) seconds:: #308e30 stack
end
end
when green flag clicked
motor [B v] set power to (100)%:: #308e30 stack
forever
if <key [up arrow v] pressed?> then
motor [B v] turn [this way v] for (0.1) seconds:: #308e30 stack
end
end
- RexNeff
-
Scratcher
8 posts
How to move an ev3 motor while the keyboard arrow is pressed
I used the following script, but it does the same as the script above. It would be smoother if you could make the motor not on and off,but rather continuous.
Just replace the 0.1 seconds with any way you have for making the motor continuous, and it will stop buffering.
when green flag clicked
forever
if <key [ arrow key] pressed?> then
repeat until <not <key [ arrow key] pressed?>>
motor [ B] turn this way for [ 0.1] seconds
end
end
Just replace the 0.1 seconds with any way you have for making the motor continuous, and it will stop buffering.
Last edited by RexNeff (June 8, 2024 03:56:24)
- Discussion Forums
- » Connecting to the Physical World
-
» How to move an ev3 motor while the keyboard arrow is pressed