05.05.2014 Views

csmstr - Omega Engineering

csmstr - Omega Engineering

csmstr - Omega Engineering

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CONFIGURING PROGRAMS<br />

PROGRAMMING TIPS<br />

Crimson will most likely misunderstand exactly which actions you want to be dependent<br />

upon the if condition. Although line breaks are recommend between actions, they are not<br />

used to figure out what is and is not included within the conditional statement.<br />

SWITCH STATEMENTS<br />

A switch statement is used to compare an integer value against a number of possible<br />

constants, and to perform an action based upon which value is matched. The exact syntax<br />

supports a number of options beyond those shown in the example below, but for the vast<br />

majority of applications, this simple form will be acceptable.<br />

The architecture of the switch statement is as follow…<br />

switch ( int var) {<br />

case 1:<br />

action1;<br />

break;<br />

case 2:<br />

action2;<br />

…<br />

default:<br />

action3;<br />

break;<br />

}<br />

This example below will start a motor selected by the value in the MotorIndex tag...<br />

switch( MotorIndex ) {<br />

case 1:<br />

MotorA := 1;<br />

break;<br />

case 2:<br />

case 3:<br />

MotorB := 1;<br />

break;<br />

case 4:<br />

MotorC := 1;<br />

break;<br />

default:<br />

MotorD := 1;<br />

break;<br />

}<br />

A value of 1 will start motor A, a value of 2 or 3 will start motor B, and a value of 4 will start<br />

motor C. Any value which is not explicitly listed will start motor D. Things to note about the<br />

syntax are the use of curly-brackets around the case statements, the use of break to end each<br />

conditional block, the use of two sequential case statements to match more than one value,<br />

and the use of the optional default statement to indicate an action to perform if none of the<br />

specified values is matched by the value in the controlling expression. (If this syntax looks<br />

REVISION 6 PAGE 231

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!