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...
$pressed = 0
2.) From the ARC menu ribbon, add a "Mobile interface" control by clicking on Project then Add Controls, Mobile, then Interface Builder.
3.) Click on the gear icon on the mobile control to open the configuration menu.
4.) Add a "Forwards" button to the mobile control.
5.) Click on the "Forwards" button, then on the lower right of the mobile control, click on "Edit Script tab...
and copy in the following script...
$pressed = 1
$pressed = 0
6.) Click "Save" on the script editor, then click "Save" on the mobile control.
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.