View unanswered posts | View active topics It is currently Sat Oct 25, 2014 11:38 am






Reply to topic  [ 2 posts ] 
Arm and Limit Switch Project Not Working Correctly 
Author Message
Rookie
User avatar

Joined: Tue May 01, 2012 9:55 pm
Posts: 3
Post Arm and Limit Switch Project Not Working Correctly
The idea here is to have my arm lift to the top, hit the limit switch, and then swing down. Once it hits the bottom limit switch, it goes back up and repeats.

Can anyone tell what's wrong? It won't compile.

Here is my current program, and the error messages below it; any help would be appreciated.
Code:
task main()
{
   while(1 == 1)
   
{
  if (SensorValue[touchSensor1]==1) && (SensorValue[touchSensor2]==0) || (SensorValue[touchSensor1]==0) && (SensorValue[touchSensor2]==0);
  motor[Arm] = -20;

else if(SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2]==1) || (SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2] ==0);
  motor[Arm] = 20;
}

}


Here are the error messages I receive when attempting to compile. First 6 error messages are for the first if statement, and the rest are for the second.

File "ArmTrials5-13-12.c" compiled on May 13 2012 17:31:15
**Error**:Unexpected scanner token-> '&&'
**Error**:Unexpected scanner token-> '('
**Error**:Missing ';' before ')'
**Error**:Unexpected scanner token-> ')'
**Error**:Unexpected scanner token-> '||'
*Warning*:Meaningless statement. Did you mean '=' instead of '=='?
**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected scanner token-> 'if'
**Error**:Unexpected scanner token-> '('
**Error**:Missing ';' before ')'
**Error**:Unexpected scanner token-> ')'
**Error**:Unexpected scanner token-> '&&'
**Error**:Unexpected scanner token-> '||'
*Warning*:Meaningless statement. Did you mean '=' instead of '=='?


Sun May 13, 2012 6:39 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Arm and Limit Switch Project Not Working Correctly
The errors are occurring because your syntax is incorrect. Here is the syntax that will make those errors go away:
(P.S. next time you post code, please put it in "code" tags)

Code:
task main()
{
  while(1 == 1)   
  {
    if((SensorValue[touchSensor1]==1) && (SensorValue[touchSensor2]==0) || (SensorValue[touchSensor1]==0) && (SensorValue[touchSensor2]==0))
    {
      motor[Arm] = -20;
    }
    else if((SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2]==1) || (SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2] == 0))
    {
      motor[Arm] = 20;
    }
  }
}

You need parentheses around the condition in the if statement, and there can't be a semicolon at the end if you want it do actually do anything. You might want to look at some C syntax for the basics, and ROBOTC has some great tutorials here: http://www.robotc.net/education/curriculum/vex/
That takes care of making it compile, but whether it does what you want it to do is a different story.

_________________
sudo rm -rf /


Sun May 13, 2012 8:25 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.