United Kingdom
Asked — Edited
Resolved Resolved by Rich!

Help With An If Script For Motor Control

I need a little help with a script. Originally I had a script on the mobile interface where if I pressed a button, the motors would drive forward, and pressed again, the motors would stop. Here's what I had using image buttons...


if (!$pressed)
Set(D1, Off)
Set(D3, Off)
PWM(D0, 70)
PWM(D2, 70)
waitforchange($Direction)

$pressed = 1
ELSE
Set(D1, Off)
Set(D3, Off)
PWM(D0, 0)
PWM(D2, 0)
waitforchange($Direction)
$pressed = 0
endif

But I have now changed the mobile image buttons to direction button's (along with a custom Movement Panel which is fully scripted with PWM commands) so they can interface with ping sensors, so changed the above script to the following...

if (!$pressed)
Forward()
waitforchange($Direction)
$pressed = 1

ELSE
Stop()
waitforchange($Direction)
$pressed = 0
endif

so pressing the button once moves the motors forward, but pressing it again no longer stops the motors. What do I need to change in the second script to get what I'm after?

Thanks.


ARC Pro

Upgrade to ARC Pro

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro

United Kingdom
#2  

I never had a stop button. I'm trying not to use a stop button to limit the amount of buttons on the mobile control. I have my control buttons laid out a certain way and would like to keep them that way if possible.

PRO
Synthiam
#3  

Here you go...

  1. Make sure you have initiated the variable in your On Connection script or somewhere before attempting to use it in an IF condition (see video demonstration)

  2. You can always test a script using the RUN command while editing (See video demonstration)

United Kingdom
#4  

Thanks DJ.

I already have a variable in my connection script which I used with the first script I posted, so no worries there. I was already aware of, and use the "Run" option when writing a script. I tried to play the video you posted, but it's not working, saying " This is a duplicate video that has already been uploaded".

United Kingdom
#6  

Lol, now it's asking me to sign in to watch the video. Do you have it set to private?

PRO
Synthiam
#7  

I'll check. YouTube really messed this video upload up! Lol they must be have some technical issues.