<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.robotc.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;feed=atom&amp;action=history</id>
		<title>Using switch statements - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;action=history"/>
		<updated>2013-05-18T13:03:03Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.18.0</generator>

	<entry>
		<id>http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;diff=3453&amp;oldid=prev</id>
		<title>Bfeher at 20:31, 15 May 2012</title>
		<link rel="alternate" type="text/html" href="http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;diff=3453&amp;oldid=prev"/>
				<updated>2012-05-15T20:31:46Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 20:31, 15 May 2012&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 27:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 27:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;|}&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;|}&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This is an example of a struct. If you have multiple arms on your robot, you can have a struct to hold the properties of each one.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;A struct is implemented, and its components are accessed like this:&amp;lt;br /&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;{|&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;|-&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;|&amp;lt;syntaxhighlight lang=&amp;quot;ROBOTC&amp;quot;&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;robotArm leftArm;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;leftArm.maxPos = 2000;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;leftArm.minPos = 150;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;leftArm.armSpeed = 100;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;|}&amp;lt;br /&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;{{tip-from-author|name=jpearman|link=http://www.vexforum.com/showpost.php?p=221035&amp;amp;postcount=8}}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;{{tip-from-author|name=jpearman|link=http://www.vexforum.com/showpost.php?p=221035&amp;amp;postcount=8}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bfeher</name></author>	</entry>

	<entry>
		<id>http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;diff=3452&amp;oldid=prev</id>
		<title>Bfeher: Created page with &quot;{{DISPLAYTITLE: Using Switch Statements}} &lt;yambe:breadcrumb self=&quot;Using Switch Statements&quot;&gt;Programming_Tips_Tricks|Programming Tips Tricks&lt;/yambe:breadcrumb&gt; &lt;br /&gt;  Here's an...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.robotc.net/w/index.php?title=Using_switch_statements&amp;diff=3452&amp;oldid=prev"/>
				<updated>2012-05-15T20:31:33Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{DISPLAYTITLE: Using Switch Statements}} &amp;lt;yambe:breadcrumb self=&amp;quot;Using Switch Statements&amp;quot;&amp;gt;Programming_Tips_Tricks|Programming Tips Tricks&amp;lt;/yambe:breadcrumb&amp;gt; &amp;lt;br /&amp;gt;  Here&amp;#039;s an...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE: Using Switch Statements}}&lt;br /&gt;
&amp;lt;yambe:breadcrumb self=&amp;quot;Using Switch Statements&amp;quot;&amp;gt;Programming_Tips_Tricks|Programming Tips Tricks&amp;lt;/yambe:breadcrumb&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here's another tip demonstrating the use of the switch statement.&lt;br /&gt;
&lt;br /&gt;
Let's say you have a motor that you want to drive forward if you press one button and backwards if you press a different button. If you press both or neither buttons the motor should be stopped. You could program this with cascaded if..then..else statements but another way is to combine the two buttons into one variable and use a switch statement. The &amp;quot;&amp;lt;&amp;lt;&amp;quot; is a shift left operator which is often used instead of multiply by 2. DriveLiftMotor would be a function to actually send values to the motor. Everything in capitals are constants defined elsewhere in the code:&amp;lt;br /&amp;gt;&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;ROBOTC&amp;quot;&amp;gt;&lt;br /&gt;
// LiftCtl will be 0, 1, 2 or 3 depending on which buttons are pressed&lt;br /&gt;
LiftCtl = (vexRT[ LIFT_DN_BUTTON ] &amp;lt;&amp;lt; 1) + vexRT[ LIFT_UP_BUTTON ];&lt;br /&gt;
&lt;br /&gt;
switch( LiftCtl )&lt;br /&gt;
    {&lt;br /&gt;
    case    1:  // first button pressed&lt;br /&gt;
        DriveLiftMotor( LIFT_UP_SPEED );&lt;br /&gt;
        break;&lt;br /&gt;
    case    2: // second button pressed&lt;br /&gt;
        DriveLiftMotor( LIFT_DN_SPEED );&lt;br /&gt;
        break;&lt;br /&gt;
    default:  // either neither or both buttons pressed&lt;br /&gt;
        DriveLiftMotor( 0 );&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is an example of a struct. If you have multiple arms on your robot, you can have a struct to hold the properties of each one.&lt;br /&gt;
&lt;br /&gt;
A struct is implemented, and its components are accessed like this:&amp;lt;br /&amp;gt;&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;ROBOTC&amp;quot;&amp;gt;&lt;br /&gt;
robotArm leftArm;&lt;br /&gt;
leftArm.maxPos = 2000;&lt;br /&gt;
leftArm.minPos = 150;&lt;br /&gt;
leftArm.armSpeed = 100;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{tip-from-author|name=jpearman|link=http://www.vexforum.com/showpost.php?p=221035&amp;amp;postcount=8}}&lt;/div&gt;</summary>
		<author><name>Bfeher</name></author>	</entry>

	</feed>