All Tutorials / Steve G / Setting Servo speeds and Initialization Script Tutorial

Setting Servo speeds and Initialization Script Tutorial

Step 4. Init scripts using varables.

Some scripts use variables, and some of these scripts need a primer to set the variable to be used. The following example sets a variable to be used with the Mobile Interface Control. This variable allows you to have two uses for one button which is great for saving space on the mobile control, as you only need one button instead of having two. The following example can be used to drive a robot forwards then to stop it from moving, and assumes you have a movement control panel already added to your project.

1.) In a "Connection" script, either in the "Connection Control" script editor, or in a connection script in a script manager like was explained in steps 1 and 2, enter the following "Init" script and save it...

Code:

$pressed = 0



User-inserted image

2.) From the EZ-Builder menu ribbon, add a "Mobile interface" control by clicking on Project then Add Controls, Mobile, then Interface Builder.

User-inserted image

3.) Click on the gear icon on the mobile control to open the configuration menu.

User-inserted image

4.) Add a "Forwards" button to the mobile control.

User-inserted image

5.) Click on the "Forwards" button, then on the lower right of the mobile control, click on "Edit Script tab...

User-inserted image

and copy in the following script...

Code:

if (!$pressed)
Forward()
$pressed = 1
ELSE
Stop()
$pressed = 0
endif



6.) Click "Save" on the script editor, then click "Save" on the mobile control.

User-inserted image

User-inserted image

7.) Power on your EZ-B and connect it to your EZ Builder project. When the connection is made, the "Init" script will automaticly run and the "!$pressed" varable will be set. When you press the "Forwards" button on your mobile interface control, the motors on your robot should move. When you press the same button again, the motors will stop.