View unanswered posts | View active topics It is currently Tue Nov 12, 2019 7:18 pm






Reply to topic  [ 2 posts ] 
!= condition and const short 
Author Message
Rookie

Joined: Wed Jun 03, 2015 8:53 am
Posts: 1
Post != condition and const short
While trying to learn about how to program the VEX LCD screen I came across this sample code. The full code is actually in the robotc sample programs. The first thing I don't understand is the != condition, which can be seen below. In the full code you can see the const short near the top which is unfamiliar to me. If someone could help it would be much appreciated.
Code:
task main()
{
//Declare count variable to keep track of our choice
int count = 0;
 
//------------- Beginning of User Interface Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Loop while center button is not pressed
while(nLCDButtons != centerButton)
{
//Switch case that allows the user to choose from 4 different options
switch(count){
case 0:
//Display first choice
displayLCDCenteredString(0, "Autonomous 1");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count = 3;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 1:
//Display second choice
displayLCDCenteredString(0, "Autonomous 2");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count--;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 2:
//Display third choice
displayLCDCenteredString(0, "Autonomous 3");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count--;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 3:
//Display fourth choice
displayLCDCenteredString(0, "Autonomous 4");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count--;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count = 0;
}
break;
default:
count = 0;
break;
}
}
//------------- End of User Interface Code ---------------------


Wed Jun 03, 2015 11:23 am
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: != condition and const short
!= means not equal to. This is the same as writing !(nLCDButtons == centerButton) which is read "not" nLCDButtons equals centerButton.

So const short would be difficult to google but that is mainly because it is 2 separate things. Const(constant) means that the variable does not change after it is set initially. Defining which number refers to which button would be a good example because no other code should change which number responds to which button. Short is a data type just like int or char that stores numbers just like int but takes up less space in the robots memory. Shorts are good if you don't need a variable to be able to store numbers in the billions.


Wed Jun 03, 2015 12:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.