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.
Β