12.1.8 Exercise

This section explains the basics of the feature. Please utilize the feature according to your site environment.

Exercise: Using Rotation Feature Periodically

You can move the second hand of the clock with the script.

(1) Object Configuration

a) Register an analog tag named ‘ROTATE_SEC’.

b) Double-click the second-hand object to bring up the [Object Configuration] window. Select the [Rotate] feature and configure the object as shown below.

c) In the [Rotate] tab, you must assign the ‘Center Point’. To find the coordinate, place the mouse cursor on the center point. You will find the coordinate at the right-bottom of the XpanelDesigner.

(2) Script

a) Select [Tools] – [Script] – [New Script] to bring up the [Add Script] window. Set the running type as ‘Period’ then set the period as 1 sec.

b) Write the script as shown below. When the value of the “ROTATE_SEC” reaches or exceeds 360, the script will store 6 to the tag to continue the rotation. The object will rotate 6° per second.

VAR A;          //Declare variable A

A=ROTATE_SEC;        //Save ROTATE_SEC value to A

IF(A>=360)

{

ROTATE_SEC=6;        //ROTATE_SEC becomes 6 when it reaches 360

}

ELSE

{

ROTATE_SEC=A+6;        //Object rotates 6 degrees per sec

}

c) Compile the script to finish the programming.

(3) Checking the Operation

a) Write the project to Xpanel or execute the project with the simulator. You will find that the second-hand object rotates each second.